大佬们,为什么我这个错了啊,求指点~~

P1914 小书童——凯撒密码

红染月暮 @ 2020-12-23 08:18:44

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

    return 0;
}

by metaphysis @ 2020-12-23 15:41:48

@红染月暮

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[])
{
    int n;
    char a;
    cin >> n;
    while(cin >> a) printf("%c", 'a' + ((a - 'a') + n) % 26);
    return 0;
}

|