scanf("%d%s", &n,a);与gets(a);的区别?

P1914 小书童——凯撒密码

AzMat_AMAQ @ 2021-12-11 20:21:28

#include<stdio.h>
int main() {
    char a[100];
    int n;
    scanf("%d%s", &n,a);
    //getchar();
    //gets(a);
    for (int i = 0; a[i]!='\0'; i++) {
        if ('z'-a[i]<n%26) {
            a[i] = 'a' + (n % 26) - ('z' - a[i])-1;
        }
        else a[i] = a[i] + n%26;
    }
    for (int i = 0; a[i] != '\0'; i++)putchar(a[i]);
    //puts(a);
}

by ajahjahah @ 2021-12-11 20:22:24

@AzMat_AMAQ 你谷对gets不友好


by AzMat_AMAQ @ 2021-12-11 20:24:59

scanf("%d%s", &n,a); //getchar(); //gets(a); 这两个的区别? scanf_s("%d", &n); getchar(); gets_s(a); 可以在vs上运行,但不能在这个上面运行。


by xzx_thanks_star @ 2021-12-11 20:32:07

@AzMat_AMAQ

gets要用c++11才行


by ud2_ @ 2021-12-11 20:36:44

@AzMat_AMAQ


by AzMat_AMAQ @ 2021-12-11 20:52:13

谢谢各位的帮助,我解决这个问题了


|