Walker_Sama @ 2021-11-11 21:23:36
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
int n;
cin>>n;
cin>>str;
for(int i=0;i<str.size();i++){
if(str[i]>='a' && str[i]<='z'){
str[i]=str[i]+n;
}
cout<<str[i];
}
return 0;
}
by ningago @ 2021-11-11 21:30:32
@Oscar_Young
str[i] + n > 'z' 需特判
题面z 的下一个字母是 a
by _hello_w_ @ 2021-12-17 20:39:28
你这个解题思路不全,没有考虑n>26以上的情况,
int n;
string a;
char b[55];
int main()
{
cin>>n>>a;
for (int i = 0; i < a.size(); i++)
{
b[i] = (a[i] + n - 97) % 26 +'a';
}
for (int i = 0; i < a.size(); i++) cout<<b[i];
return 0;
}