chenchenwwww @ 2020-02-01 13:14:34
#include<cstdio>
#include<cstring>
int main()
{
char ch[100];
int n;
scanf("%d",&n);
n = n%26;
scanf("%s",ch);
for(int i=0;i<strlen(ch);i++)
{
ch[i] = ch[i] +n;
if(ch[i]>'z') ch[i] = ch[i] -26;
}
printf("%s",ch);
return 0;
}
by SCHHCS @ 2020-02-01 23:18:28
ch[i]=ch[i]+n有问题。原因是加n后可能会溢出ask码表的范围。for循环里应改成: while(ch[i]+n>'z') ch[i]=ch[i]-26; ch[i]=ch[i]+n;
by chenchenwwww @ 2020-02-03 09:28:49
@SCHHCS 感谢!!