为啥总是%60的通过率,哪位大佬帮忙看看!

P1914 小书童——凯撒密码

XU19337615357 @ 2023-07-15 19:13:58

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    string ch;
    cin>>n>>ch;
    for(int i=0;i<ch.size();i++)
    {
        ch[i]=ch[i]+n;
        if(ch[i]>122)
            ch[i]=ch[i]%122+96;
    }
    cout<<ch;
}

by gtafics @ 2023-07-15 19:16:27

百分之六十写作60%。


by AIMEE11 @ 2023-07-15 19:21:05

先说下,i 定义了两次不过这不是主要问题(


by AIMEE11 @ 2023-07-15 19:28:33

@XU19337615357

for(i=0; i<ch.size(); i++) {
        for(j=1; j<=n; j++) { //直接减过不了               
            s[i]++;
            if(s[i]>'z') s[i]-=26;
        }
    }

by AIMEE11 @ 2023-07-15 19:31:14

靠,打错了,ch[i]


by LiJoQiao @ 2023-07-15 19:32:04

@XU19337615357 应-'a'+1后对26取模再加回来


by XU19337615357 @ 2023-07-15 20:01:32

@LiJoQiao一样的结果呀!通过率还是那么多,过不了


by zhuyongkang123 @ 2023-07-15 20:24:34

@XU19337615357 n>=26会怎么// n = 25 ch = abcxyz试一逝// 'b'+25-26 'b'-1答案居然不一样


|