40分,3,4,5点WA

P1914 小书童——凯撒密码

nick_zha @ 2021-04-23 18:36:12

#include<iostream>
#include<string>
using namespace std;
int main() 
{
    int a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0;i<b.size();i++)
    {
        int c;
        c=(int)b[i]-96;
        c+=a;
        if(c%26==0) 
        {
            c=1;    
        }
        else {c%=26;}
        c+=96;
        cout<<(char)c;
    }
    return 0;
}

by nick_zha @ 2021-04-23 18:39:32

#include<iostream>
#include<string>
using namespace std;
int main() 
{
    int a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0;i<b.size();i++)
    {
        int c;
        c=(int)b[i]-96;
        c+=a;
        if((int)c%26==0)    
        {
            c=1;    
        }
        else {c%=26;}
        c+=96;
        cout<<(char)c;
    }
    return 0;
}

最新代码,还是40分,凸(艹皿艹 )


by 落河之秋 @ 2021-04-23 18:52:58

#include<string>
#include<iostream>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    for(int i=0; i<s.size(); i++)
    {
        for(int j=0; j<n; j++)
        {
            s[i]++;
            if(s[i]>'z')
            {
                s[i]='a';
            }
        }
    }
    cout<<s;
    return 0;
}

by 落河之秋 @ 2021-04-23 18:53:54

每加一判断一次 比z大了就换成a


by Heyf @ 2021-04-23 19:05:46

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    n%=26;
    char ch;
    while(cin>>ch) cout<<((ch+n)>'z'?(char)(ch+n-26):(char)(ch+n));
    return 0;
} 

判断简单一点吧不用挨着加


by nick_zha @ 2021-04-24 15:06:05

加了个判断,得了80分,什么鬼操作第4个点WA

#include<iostream>
#include<string>
using namespace std;
int main() 
{
    int a;
    string b;
    cin>>a;
    cin>>b;
    if(a%26==0)
   {
    cout<<b;return 0;
   }
    for(int i=0;i<b.size();i++)
    {
        int c;
        c=(int)b[i]-96;
        c+=a;
        if((int)c%26==0)    
        {
            c=1;    
        }
        else {c%=26;}
        c+=96;
        cout<<(char)c;
    }
    return 0;
}

by nick_zha @ 2021-04-24 15:08:45

2ms/624.00KB
WA
Wrong Answer. wrong answer On line 1 column 1, read a, expected z.

|