第四个测试点寄了,大佬们为啥

P1914 小书童——凯撒密码

Hopoyage @ 2023-10-09 15:01:06

#include<iostream>
using namespace std;
int main(){
    int n,temp;
    string str;
    cin >> n;
    cin >> str;
    for(int i = 0;i < str.length();i++){
        temp = str[i]+n;
        if(temp > 122){
            temp = 97;
        }
        str[i] = (char)temp;
    }
    cout << str;
    return 0;
}

by zhouyk0501 @ 2023-10-09 15:10:51

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    char a[50];
    cin>>a;
    int k;
        int len=strlen(a);
    for(int i=0;i<len;i++){
        k=a[i]+n;
        if(k>'z'){
            k=k-26;
        }
        char h=k;
        cout<<h;
    }
    return 0;
}

|