为什么只有80分,求解

P1914 小书童——凯撒密码

qq3179436190 @ 2017-08-20 22:28:03

var n,i,len:integer;s:string;
begin
readln(n);
if n>=26 then n:=n mod 26;
if n<=-26 then n:=(abs(n) mod 26)*-1;
read(s);
len:=length(s);
for i:=1 to len do
s[i]:=chr(ord(s[i])+n);
if (ord(s[i])>ord('z')) then 
s[i]:=chr(ord(s[i])-ord('z')+ord('a')-1);
if (ord(s[i])<ord('a')) then 
s[i]:=chr(ord(s[i])+ord('z')-ord('a')+1);
for i:=1 to len do write(s[i]);
end.

by EK_KING_ @ 2017-08-30 15:13:12

var
i,k,n:longint;
s:string;
begin
readln(k);
readln(s);
n:=length(s);
for i:=1 to n do
begin
s[i]:=chr(ord(s[i])+k);
if ord(s[i])>122 then s[i]:=chr(ord(s[i])-26);
end;
write(s);
end.

by EK_KING_ @ 2017-08-30 15:13:32

这是正确的


by Hanabi_BNUAZ @ 2017-09-03 12:05:29

第四组数据我下载了,input是:

25 abcxyz

output是:

zabwxy

你不妨用这组数据试一下,至于程序我的程序是这样的:

#include<bits/stdc++.h>
using namespace std;
char s[100000100];
int main()
{
    long long n,i;
    cin>>n;
    gets(s);
    gets(s);
    for (i=0;i<strlen(s);i++)
    {
        if (s[i]+(n%26)>'z') s[i]=s[i]-'z'+'a'-1;
        s[i]+=(n%26);
        while (s[i]>'z') s[i]=s[i]-'z'+'a'-1;
        cout<<s[i];
    }
    return 0;
}

|