为啥全WA!!!!

P1914 小书童——凯撒密码

gnidocon @ 2024-12-03 21:37:06

#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,i = 0,j = 0;
    char ori[51];
    cin >> n;
    getchar();
    while((ori[i++] = getchar())!= '\n' && i <= 51) 
        ori[i-1] = (ori[i-1] -'a' + n) % 26 + 'a';  
    ori[i] = '\0';
    while(ori[j++] != '\0')
        cout << ori[j-1];

    return 0;
 } 

by gnidocon @ 2024-12-05 17:48:06

在本地测试几个数据都是对的,,,


by EASONWHT @ 2024-12-21 21:13:14

@gnidocon 支持互关^_^:

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

|