样例没问题,但是全WA,求助大佬

P1914 小书童——凯撒密码

HNZZT @ 2023-11-15 11:03:34

#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char y[27] = "abcdefghijklmnopqrstuvwxyz";
    int n;
    cin >> n;
    getchar();//吞掉回车
    char a[55];
    cin.getline(a, 55);
    int len = strlen(a);
    for (int i = 0;i < len;i++) {
        for (int k = 0;k < 26;k++) {
            if (a[i] == y[k]) {
                a[i] = y[(k+=n) % 26];
            }
        }
    }
    cout << a;
    return 0;
}

by Yukino_suki @ 2023-11-16 10:25:19

@HNZZT

不用吞回车,删掉“getchar()”之后就行了


by Yukino_suki @ 2023-11-16 10:26:08

@HNZZT

然后把输入改成“cin>>a;”就行了


by HNZZT @ 2023-11-17 16:50:40

@LH_sama okok谢谢大佬


|