为什么是80分。蒟蒻求助

P1914 小书童——凯撒密码

d3NtMDAw @ 2017-02-11 09:42:21

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    n%=26;
    int i=0,j;
    char a[100];
    cin>>a;
    while(a[i]!='\0')
    {
        for(j=1;j<=n;++j)
        {
            ++a[i];
            if(a[i]>'z')
            a[i]='a';
        }
        i++;  
    }
    cout<<a<<endl;
    return 0; 
}  

by 蒟蒻lxy @ 2017-02-15 21:26:48

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    string a;
    cin>>n;
    cin>>a;
    if (n==26)
    {
        cout << a << endl; return 0;
    }
    for (int i=0;i<=a.size();i++)
    {
        if (a[i]+n>122)
        {
            a[i]=a[i]+n-26;
        }
        else
        {
            a[i]=a[i]+n;
        }
    }
    cout << a << endl;
    return 0;
}
应该这样

by skiyalg @ 2017-02-22 20:04:13

你只考虑了大于122的。小于97也要想


by CrTsIr400 @ 2020-07-04 19:02:52


|