求教,为什么80分过不去?

P1914 小书童——凯撒密码

樱花沐月 @ 2017-01-16 22:02:37

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char str[1000];
int n, i, x, s;
int main()
{
    cin >> n;
    scanf("%s", &str);
    if (n == 26) {
        cout << str;
        return 0;
    }
    x = strlen(str);
    for (i = 0;i < x;i++) {
        if (str[i] >= 'A' && str[i] <= 'Z') str[i] = char(int(str[i]) + 'a' - 'A');
        if (str[i] == 'z') str[i] = char(96);
        s = int(str[i]) + n % 26;
        if (s > 122) s = s - 122 + 96;
        str[i] = char(s);
    }
    cout << str;
    return 0;
}

by xiajieke @ 2017-01-22 16:25:51

#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,k;
char a[100];
scanf("%d %s",&n,ch);
int l=strlen(ch);
for(i=0;i<l;i++)
{
a[i]=((a[i]-'a')+n)%26+('a');
}
puts(a);
return 0;
}

|