自测数据点都是对的,可是还是全WA 0分,求大佬求解!

P1914 小书童——凯撒密码

Griezmann_7 @ 2023-09-04 22:19:34

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main() {
    int n;
    char a[100];
    int b=0;
    cin >> n;
    cin.get();//消除换行符
    cin.getline(a, 100);
    int length = strlen(a);
    for (int i = 0; i <= length-1 ; i++) {
        b = a[i] + n;//用ASCII码来运算
        if (b <= 122) {//'z'的ASCII码为122
            cout << char(b);//将ASCII码转化为字符输出
        }
        else {
            for (int j = 1;; j++) {
                b -=26;
                if (b <= 122)break;
            }//for循环用来处理超出z的部分,轮回到a开始
            cout << char(b);//将ASCII码转化为字符输出
        }
    }
}

by tuiqian666 @ 2023-09-04 22:50:56

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main() {
    int n;
    char a[100];
    int b=0;
    cin >> n;
    cin.get();//消除换行符
    cin >> a;
    int length = strlen(a);
    for (int i = 0; i <= length-1 ; i++) {
        b = a[i] + n;//用ASCII码来运算
        if (b <= 'z') {//'z'的ASCII码为122
            cout << char(b);//将ASCII码转化为字符输出
        }
        else {
            for (int j = 1;; j++) {
                b -=26;
                if (b <= 'z')break;
            }//for循环用来处理超出z的部分,轮回到a开始
            cout << char(b);//将ASCII码转化为字符输出
        }
    }
}

兄弟洛谷不能用getline诶


by Griezmann_7 @ 2023-09-05 21:36:08

跪谢兄弟!!!问题解决了


|