Haidde @ 2024-02-11 10:10:15
#include<stdio.h>
int main()
{
int n,i;
char s[55];
scanf("%d",&n);
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{if(s[i]+n>122)
s[i]=s[i]+n-122;
else s[i]+=n;}
printf("%s",s);
return 0;
}
by xiangzhenze611 @ 2024-02-11 10:22:45
by xiangzhenze611 @ 2024-02-11 10:28:25
#include<stdio.h>
int main()
{
int n,i;
char s[55];
scanf("%d",&n);
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{if(s[i]+n>'z')
s[i]=s[i]+n-26;//只有26个字母
else s[i]+=n;}
printf("%s",s);
return 0;
}
另外,这正是一个奇怪的码风
by xiangzhenze611 @ 2024-02-11 10:32:19
@Haidde 小写字母 s[i]=s[i]+n-122;
是错误的,一旦减了,它的值会变成
by Haidde @ 2024-02-16 10:15:34
@xiangzhenze61好的好的,谢谢大佬