听取WA声一片

P1914 小书童——凯撒密码

lizishi @ 2024-07-08 12:44:15

明月别枝惊鹊,清风半夜鸣蝉。
稻花香里说丰年,听取WA声一片。
#include <iostream>
#include <cstring>
using namespace std;

int main() {
    int n;
    char str[100];
    cin >> n >> str;
    for (int i = 0; i < strlen(str); i++) {
        str[i] += n;
        if (str[i] >= 'z') str[i] -= 26;
    }
    cout << str;
    return 0;
}

洛谷:40 jyshare:Time limit exceeded toolhelper:对于测试点3,编译失败。


by lizishi @ 2024-07-08 12:46:18

qwertyuiopasdfghjklzxcvbnm编译失败


by ptxy2352010111 @ 2024-07-08 13:07:18

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

int main() {
    int n;
    char str[100];
    cin >> n >> str;
    for (int i = 0; i < strlen(str); i++) {
        str[i] += n;
        if (str[i] > 'z') str[i] -= 26;
    }
    cout << str;
    return 0;
}

把等于去掉


by ptxy2352010111 @ 2024-07-08 13:10:17

去掉等于是60分```

include<bits/stdc++.h>

using namespace std; int main(){ string s; int n; cin>>n; n%=26; cin>>s; for(int i=0;i<s.size();i++){ if(s[i]-'a'+n>=26){ s[i]=s[i]+n-26; }else{ s[i]=s[i]+n; } } cout<<s; return 0; }


用这个100分

|