ljx2004_cn @ 2023-12-20 22:10:16
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string a;
int n;
cin>>n;
cin>>a;
for(int i=0;i<a.length();i++)
{
if(n>=26)
n-=26;
a[i]+=n;
}
for(int i=0;i<a.length();i++)
cout<<a[i];
return 0;
}
by No_Rest @ 2023-12-20 22:41:23
第一个 for
循环内部应该为:
a[i] += n;
if(a[i] > 'z') a[i] -= 26;
by SuperAlex4 @ 2023-12-20 23:33:07
for(int i=0; i<a.length(); i++){
a[i]+=n-26;
if(a[i]<'a') a[i]+=26;
}
by lichenxi108 @ 2023-12-21 12:27:19
输入:
1
xyz
错误答案:
yz{
预期:
yza
错误原因: x与y两个字符没问题,z字符 + 1 就是 {,所以,12 - 14行应改成:
if (n + a[i] > 'z')
a[i] = a[i] - 26 + n;
else
a[i] = a[i] + n;
by ljx2004_cn @ 2023-12-26 17:53:23
@ldf1208 哥你这样改出来也错的呀