大佬救救窝吧!! 洛谷给出的输入是3 a 可我写的没毛病啊!!

P1914 小书童——凯撒密码

Mr_hua666 @ 2021-01-19 12:15:30

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

int main() {
    char c[100] = { 0 };
    int n=0;
    cin >> n;
    if (n > 25)  n = (n - (n - 1) / 25) % 25;
    for (int i = 0; i <= 99; i++)
    {

        cin >> c[i];
        if (int(c[i] + n) <= 122)
            cout << char(c[i] + n);
        else cout << char(c[i] + n - 26);

    }
    return 0;
}

by DWT8125 @ 2021-01-19 12:24:20

重复100次输入???


by LHQing @ 2021-01-19 12:25:41

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

int main() {
    char c[100] = { 0 };
    int n=0;
    cin >> n;
    if (n > 25)  n = (n - (n - 1) / 25) % 25;
    scanf("%s",c);
    for (int i = 0; i < strlen(c); i++)
    {
        if (int(c[i] + n) <= 122)
            cout << char(c[i] + n);
        else cout << char(c[i] + n - 26);
    }
    return 0;
}

by LHQing @ 2021-01-19 12:25:56

@Mr_hua666 你那个输入完了不结束不行


by LHQing @ 2021-01-19 12:26:40

@Mr_hua666 你看你自己运行一下,他输出了rxf不结束


by Mr_hua666 @ 2021-01-19 12:27:02

换成这样就对了

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

int main() {
    char c[100] = { 0 };
    int n=0;
    cin >> n;
    if (n > 25)  n = (n - (n - 1) / 25) % 25;
    cin >> c;
    for (int i = 0; c[i]!='\0'; i++)
    {

        if (int(c[i] + n) <= 122)
            cout << char(c[i] + n);
        else cout << char(c[i] + n - 26);

    }
    return 0;
}

可是我觉得重复应该也没毛病吧? 谢谢大佬


by LHQing @ 2021-01-19 12:27:50

@Mr_hua666 他运行完了要结束,你不结束当然会错


by Mr_hua666 @ 2021-01-19 12:28:08

@LHQing 谢谢大佬!!


by LHQing @ 2021-01-19 12:37:17

@Mr_hua666 可以打开我的主页点关注哦


|