panrong @ 2023-10-05 10:19:41
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
char a[55],b[55];
cin>>a;
for(int i=0;i<strlen(a);i++){
b[i]=a[i]+n;
if(b[i]>'z'){
b[i]-=26;
}
cout<<b[i];
}
return 0;
}
by zhouzihang3 @ 2023-10-05 10:22:44
怎么说,谢谢您的评论,我才发现这道题我80分
by zhouzihang3 @ 2023-10-05 10:27:46
n有可能大于26,所以
#include<bits/stdc++.h>
using namespace std;
string a;
long long n;
int main(){
cin>>n>>a;
for(int i=0;i<a.size();i++){
int x=a[i]+n-'a';
x%=26;
cout<<(char)(x+'a');
}
return 0;
}
by qianhaoyu @ 2023-10-06 11:10:14
ASCII中的最大值是127,所以如果n=26时,字符'f'和后面的字符就会出错。
//```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string a;
cin>>n>>a;
int ls=0;//临时记录当前加上n的值
for(int i=0;i<a.size();i++){
ls=a[i]+n;
while(ls>'z'){
ls-=26;
}
a[i]=ls;
}
cout<<a;
return 0;
}
by qianhaoyu @ 2023-10-06 11:13:15
(我才不会告诉你我也和你一样错了)