dalao求助60 34WA

P1914 小书童——凯撒密码

Rain3721 @ 2024-11-29 16:24:36

#include<iostream>
using namespace std;
int main(){
    int n; cin>>n;
    string s; cin>>s;
    int l=s.length();
    int temp;
    for(int i=0;i<l;i++){
        s[i]+=n;
        if(s[i]>122){
            temp=(s[i]-123)%26;
            s[i]='a'+temp;
        }
    }
    cout<<s;
    return 0;
}

by ztse9172 @ 2024-12-01 18:21:18

很简单,看代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    string s;  
    cin >> n;
    cin >> s;
    string a = "";
    for (int i = 0; i < s.length(); ++i) {
        char c = s[i];
        c = ((c - 'a' + n) % 26) + 'a';
        a += c;
    }
    cout << a << endl;
    return 0;
}

by Rain3721 @ 2024-12-13 17:00:22

@ztse9172ok过了谢谢


|