大佬帮忙看一下!

P1914 小书童——凯撒密码

taohuanyu @ 2024-12-15 09:55:32

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,len;
string s1,s2;
cin>>n;
cin>>s1;
for(int i=0;i<=25;i++)
  s2[i]='a'+i;
s2+=s2;
s2+=s2;
len=s1.size();
for(int i=0;i<=len;i++)
  s1[i]=s2[s1[i]-'a'+n];
cout<<s1;
return 0;
} 

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

@taohuanyu 支持互关^_^:

#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;
}

|