hlx6032 @ 2023-12-13 15:38:48
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a[50];
int n,i,j;
scanf("%d\n",&n);
n=n%26;
do
{
a[i]=getchar();
i++;
}while(a[i-1]!='\n');
for(j=0;j<i-1;j++)
{
if(a[j]>='a'&&a[j]<='z')
{
if (a[j]>'z'-n)
a[j]=a[j]-26+n;
else
a[j]+=n;
}
printf("%c",a[j]);
}
return 0;
}
by lpk1118 @ 2023-12-13 15:47:48
第7行,是不是忘给i赋值了
by hlx6032 @ 2023-12-13 15:52:12
@lpk1118 加了之后结果还是Runtime Error
by lpk1118 @ 2023-12-13 16:11:57
@hlx6032 啊这
by TrueHoward @ 2023-12-15 16:20:19
同问……
by sdyzpf @ 2023-12-20 15:32:46
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a[50];
int n,i,j;
scanf("%d\n",&n);
n=n%26;
do
{
a[i]=getchar();
i++;
}while(a[i-1]!=EOF);
for(j=0;j<i-1;j++)
{
if(a[j]>='a'&&a[j]<='z')
{
if (a[j]>'z'-n)
a[j]=a[j]-26+n;
else
a[j]+=n;
}
printf("%c",a[j]);
}
return 0;
}
@hlx6032 @TrueHoward
把'\n'换成EOF就行了,这题输入末尾没有换行符。