这题为什么才给我60分,各位大神帮我看看

P1914 小书童——凯撒密码

pkfbc2014 @ 2015-02-14 23:06:08

#include <stdio.h>
#include <string.h>
int main()
{
char a[300];
int n,i;
    scanf("%d",&n);
scanf("%s",a);
    for(i=0;i<strlen(a);i++)
    {
        printf("%c",a[i]+n);
    }
printf("\n");
return 0;
}

谁能告诉我,为什么这样子不给过?? 求助!


by kkksc03 @ 2015-02-15 03:29:19

@[url=/space/show?uid=5070]pkfbc2014[/url] 请问,z的后面一个字母是什么


by pkfbc2014 @ 2015-02-15 11:48:03

那应该怎样改呢?


by papersnake @ 2015-02-15 16:22:26

#include <stdio.h>
#include <string.h>
int main()
{
char a[300];
int n,i;
    scanf("%d",&n);
scanf("%s",a);
    for(i=0;i<strlen(a);i++)
    {
      if(a[i]+n>'z') a[i]=a[i]-26;  //如果大于z,就减26
        printf("%c",a[i]+n);
    }
printf("\n");
return 0;
}

by farmerj777 @ 2015-07-12 17:04:15

我感觉这样写会溢出,因为我这么写就溢出了@[url=/space/show?uid=5997]papersnake[/url]


by papersnake @ 2015-07-12 20:51:02

应该不会@[url=/space/show?uid=3658]方明俊[/url]


by Mys_C_K @ 2015-08-13 21:27:45

@[url=/space/show?uid=1]kkksc03[/url] 'a'


by Bcakspace @ 2022-10-05 21:45:13

15年3k居然还会帮忙调代码!


|