请问大佬qwq,错哪里了呢?

P1914 小书童——凯撒密码

qwe400187934 @ 2020-02-11 21:04:25

#include<stdio.h>
int main(void)
{
    char ch1, ch2;
    int n;
    scanf("%d", &n);
    getchar();//吃回车
    ch1 = getchar();
    while (ch1 != EOF ) {
        ch2 = (ch1 - 'a' + n) % 26 + 'a';
        printf("%c", ch2);
        ch1 = getchar();
    }
    return 0;
}

by schtonn @ 2020-02-11 21:09:23

是不是回车吃坏了


by 北落南殇 @ 2020-02-11 21:09:43

#include<iostream>
#include<cstring>
using namespace std;

int main(){
    int n;
    string a;

    cin>>n>>a;

    for(int i=0;i<a.length();i++)
    {
        if(a[i]+n>'z')a[i]+=n-26;

        else
            a[i]+=n;

        cout<<a[i];
    }
    return 0;
}

by qwe400187934 @ 2020-02-11 21:16:57

@l_x_l 我都试了QwQ


|