求助!80 分!

P1914 小书童——凯撒密码

DANNY0926 @ 2020-10-02 19:58:33

只有80分。。。


#include<bits/stdc++.h> 
using namespace std;
int n;
string s;
int main(){
    cin>>n;
    n=n%26;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(char(s[i]+n)>'z'){
            cout<<char(s[i]+n-'z'+'a');
        }
        else if(char(s[i]+n)>'Z'&&char(s[i]+n)<'a'){
            cout<<char(s[i]+n-'Z'+'A');
        }
        else cout<<char(s[i]+n);
    }
    cout<<endl;
    return 0;
}
//输入:
25
abcxyz

//输出:
zabwxy

by DIgnited @ 2020-10-02 20:17:43

那个点错了?


by DANNY0926 @ 2020-10-02 20:19:25

第四个


by DANNY0926 @ 2020-10-02 20:20:02

(第四个点的输入输出在上面)


by zythonc @ 2020-10-02 20:25:01

@DANNY0926

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

by zythonc @ 2020-10-02 20:28:20

等等判断多余了(


by DIgnited @ 2020-10-02 20:30:08

我的代码:

打表大法好

//P1914
#include<bits/stdc++.h>
using namespace std;
char letter[27]="abcdefghijklmnopqrstuvwxyz",a[51];
int main()
{
    int n,i;
    scanf("%d%s",&n,a);
    for(i=0;i<strlen(a);i++)
        a[i]=letter[(a[i]-'0'-48+n%26-1)%26];
    printf("%s",a);
    return 0;
}

by DANNY0926 @ 2020-10-02 22:23:38

万分感谢


|