求助,测试点4过不去……

P1914 小书童——凯撒密码

Anticlockwise @ 2020-09-28 13:44:05

WA了,代码如下

#include<bits/stdc++.h>
using namespace std;
int n;
char s[100];
int main()
{
    scanf ("%d",&n);
    scanf ("%s",&s);
    if (n == 26) 
    {
        printf ("%s",s);
        return 0;
    }
    for (int i = 0;s[i] != '\0';i++)
    {
        s[i] = s[i] + n;
        if (s[i] > 'z')
        {
            s[i] = s[i] - 26;
        }
    }
    printf ("%s",s);
    return 0;
}

by metaphysis @ 2020-09-28 15:52:03

@Anticlockwise

Hack:

1000
a

by Nicrobot @ 2021-06-21 12:40:45

 s[i] = s[i] + n;

s[i]可能越界


|