lmk233 @ 2022-11-19 14:46:42
using namespace std;
int main(){
string x;
int n,c;
while(cin >> n >> x ){
for(int i=0;i<x.size();i++){
if(x[i]+n<='z'){
x[i]+=n;
}else if(x[i]+n>'z'){
c=x[i]+n-'z';
x[i]='a'+c%26-1;
}
}
cout << x << endl;
}
return 0;
}
咱也不知道为啥,我感觉已经很全面了,有没有大佬给我看看
by yanghanchen @ 2022-11-19 15:10:09
在while里面再加一个
n = n % 26;
就可以了
#include<iostream>
#include<cstring>
using namespace std;
int main(){
string x;
int n,c;
while(cin >> n >> x ){
n = n % 26;
for(int i=0;i<x.size();i++){
if(x[i]+n<='z'){
x[i]+=n;
}else if(x[i]+n>'z'){
c=x[i]+n-'z';
x[i]='a'+c%26-1;
}
}
cout << x << endl;
}
return 0;
}
完整代码