glass_a @ 2019-07-01 09:55:22
#include<stdio.h>
int main()
{
int j,n,i,k;char a[100],b[100];
scanf("%d",&n);
scanf("%s",&a);
for(k=0;a[k]<='z'&&a[k]>='a';k++);
j=n/26;
for(i=0;i<k;i++)
{
if(a[i]+n-26*j>'z')
b[i]=a[i]+n-j*26-'z'+'a';
else
b[i]=a[i]+n-26*j;
}
for(i=0;i<k;i++)
printf("%c",b[i]);
return 0;
}
by iceselen @ 2019-07-01 10:09:37
如果你用char的话,ascii在运算过程中可能会爆范围
by glass_a @ 2019-07-01 11:15:43
@iceselen 哦哦,我去看看,谢谢
by glass_a @ 2019-07-01 11:24:00
@iceselen 我用了unsigned char好像还是不行
by iceselen @ 2019-07-01 12:04:12
b[i]=a[i]+n-j*26-'z'+'a';
如果使用unsigned char在某些情况下这行代码运算过程中会产生负数,还是会暴
by glass_a @ 2019-07-01 13:52:20
@iceselen 那我交换一下顺序呢
by iceselen @ 2019-07-02 08:11:07
@glass_a 为什么这么执着于char,换int不就好了