为啥会超时啊?

P1914 小书童——凯撒密码

GNOH @ 2022-02-26 21:45:18

#include<stdio.h>
int main()
{
    int n;
    char c;
    scanf("%d\n",&n);
    while((c=getchar())!='\n')
    {
        if(c+n>123)
        {
            printf("%c",c+n-26);
        }
        else
            printf("%c",c+n);
    }
    return 0;
} 

by KevinTan @ 2022-02-26 21:52:05

@GNOH 可能是测试数据最后没有换行符,建议换一种读入


by coldy_rainy @ 2022-02-26 21:56:19

@GNOH


#include<stdio.h>
int main()
{
    int n;
    char c;
    scanf("%d\n",&n);
    while((c=getchar())!=EOF)
    {
        if(c+n>123)
        {
            printf("%c",c+n-26);
        }
        else
            printf("%c",c+n);
    }
    return 0;
} 

by GNOH @ 2022-02-26 22:28:40

@penhaochen 感谢


|