3 4点过不去

P1914 小书童——凯撒密码

tdn去世号 @ 2018-07-29 22:41:05

#include<iostream>
#include<cstdio>
using namespace std;
char m[51];
int n,i;
int main()
{
    cin>>n;
    scanf("%s",m);
    while(m[i]!=0)
    {
        m[i]=m[i]+n;
        i++;
    }
    printf("%s\n",m);
    return 0;
}

by tdn去世号 @ 2018-07-29 22:57:37

#include<iostream>
#include<cstdio>
using namespace std;
char m[51];
int n,i;
int main()
{
    cin>>n;
    scanf("%s",m);
    while(m[i]!=0)
    {
        m[i]=m[i]+n;
        while(m[i]>'z')
        {
            m[i]=m[i]-26;
        }
        i++;
    }
    printf("%s\n",m);
    return 0;
}

by 赤黒 @ 2018-07-30 00:10:23

你这个不能直接加n, 不然就算while(m[i]>'z')也没用了,直接成乱码了@铁达尼号80


|