各位大佬,我“听取WA声一片”了,求助~~~~~~~

P1914 小书童——凯撒密码

lovelinboY @ 2024-11-21 21:24:47

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

by TankmansYuanhaun26 @ 2024-11-21 21:29:26

@lovelinboY 如果是Z的话应该转化为A所以要特判


by Recursively_dumb @ 2024-11-21 21:30:12


#include<bits/stdc++.h>
using namespace std;
char a[100000000],n;
int main()
{
    scanf("%d%s",&n,a+1);
    int l=strlen(a+1);
    for(int i=1;i<=l;i++)
    {
        int f=(n+a[i]-'a'+1)%26;
        if(f==0)
            f=26;
        printf("%c",f+'a'-1);
    }
    return 0;
}

|