蒟蒻求助,WA了3个?

P1914 小书童——凯撒密码

142857142857a @ 2021-09-27 22:12:09

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

by ylinxin2010 @ 2021-09-27 22:17:50

@142857142857a

  1. s[i]+n>z
  2. s[i]=s[i]+n-26

by ylinxin2010 @ 2021-09-27 22:18:26

是'z'


by 142857142857a @ 2021-09-27 22:38:15

@ylinxin2010 谢谢大佬,已经AC了,大佬NB!


|