40分求助

P1914 小书童——凯撒密码

yuwuyanqiu @ 2023-06-17 23:30:31

#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
int main() {
 int a;
 string b;
 cin>>a>>b;
 for(int i=0;i<=b.length()-1;i++){
    cout<<char((b[i]+a)%122);
 }
    return 0;
}

不知道哪错了,过路大佬看一下


by 阿丑 @ 2023-06-18 07:56:11

@yuwuyanqiu

hack:

26
abc

by FIGFUH001 @ 2023-06-18 08:17:14

当你输入:

1
z

输出:



by zhouzihe @ 2023-06-18 08:18:10

@yuwuyanqiu

#include<bits/stdc++.h>
using namespace std;
long long int n;
string s;
int main(){
    cin>>n>>s;
    n%=26;
    for(int i=0;i<s.size();i++){
        int l=s[i]-'a';
        cout<<(char)((l+n)%26+'a');
    }
    return 0;
}

求关


by FIGFUH001 @ 2023-06-18 08:18:21

@yuwuyanqiu (输入z后不能输出a))


by liuyinuo666 @ 2023-08-23 13:40:25

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n,i,j;
    cin>>n;
    cin>>s;
    for(i=0;i<s.size();++i)
    {
        for(j=1;j<=n;++j)
        {
            ++s[i];
            if(s[i]>'z')
            s[i]='a';
        }
    }
    cout<<s;
    return 0;
}

|