本机测没错,到洛谷输出(ASCII 14)和&之类的!

P1914 小书童——凯撒密码

chenyanming @ 2018-09-30 21:47:53

#include<stdio.h>
int main()
{
    char fa[50];
    int n,i=0;
    scanf("%d",&n);
    gets(fa);
    while(fa[i]!='\0')
    {
        fa[i]+=n;
        if(fa[i]>'z')fa[i]-=26;
        i++;
    }
    puts(fa);
}

by meyi @ 2018-09-30 21:48:35

@chenyanming 不要用gets读入字符串


by WA鸭鸭 @ 2018-09-30 21:48:54

@chenyanming char到127会成中文


by chenyanming @ 2018-09-30 21:50:32


by WA鸭鸭 @ 2018-09-30 21:51:40

@chenyanming 看上面


by tumu1t @ 2018-09-30 22:06:31

@chenyanming 不要用gets,用scanf或cin


by chenyanming @ 2018-10-01 08:22:22


#include<stdio.h>
int main()
{
    char fa[50];
    int n,i=0;
    scanf("%d\n%s",&n,fa);
    while(fa[i]!='\0')
    {
        fa[i]+=n;
        if(fa[i]>'z')fa[i]-=26;
        i++;
    }
    puts(fa);
}
```![](https://cdn.luogu.com.cn/upload/pic/34995.png)

by chenyanming @ 2018-10-01 08:23:11

include<stdio.h>

int main() { char fa[50]; int n,i=0; scanf("%d\n%s",&n,fa); while(fa[i]!='\0') { fa[i]+=n; if(fa[i]>'z')fa[i]-=26; i++; } puts(fa); }


![](https://cdn.luogu.com.cn/upload/pic/34995.png)

by chenyanming @ 2018-10-01 08:24:34

#include<stdio.h>
int main()
{
    char fa[50];
    int n,i=0;
    scanf("%d\n%s",&n,fa);
    while(fa[i]!='\0')
    {
        fa[i]+=n;
        if(fa[i]>'z')fa[i]-=26;
        i++;
    }
    puts(fa);
}


by chenyanming @ 2018-10-01 08:27:06


|