求助大佬!

P1914 小书童——凯撒密码

syxnb6 @ 2022-11-16 18:22:34

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

by 07kzs @ 2022-11-16 18:38:49

@syxnb6 请看清题,并认真理解,做法有许多问题


by 07kzs @ 2022-11-16 18:41:25

@syxnb6 此为AC CODE

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

by syxnb6 @ 2022-11-16 20:35:50

@07kzs 确实确实,谢谢


|