求助大佬,为什么4个全wa?

P1914 小书童——凯撒密码

JianZhiHao @ 2019-07-28 11:12:48

include <iostream>

using namespace std; int a, b[100], c[100], k = 0, l; char h,m; int re(int x) { x = x - 26; if (x > 122) { re(x); } return x; } int main() { scanf("%d", &a); m=getchar(); for (int i = 97; i <= 122; i++) { b[k] = i; k++; } k = 0; while (1) { h = getchar(); if (h == '\n') break; l = h + a; if (l > 122) { l=re(l); } printf("%c",l);

}

return 0;

}


by 赫敏·东方延绪 @ 2019-07-28 11:16:13

希望更丰富的展现?使用Markdown


by 斗神_君莫笑 @ 2019-07-28 11:17:32

@JianZhiHao 找找上面那一行功能,有一个叫发送代码


by JianZhiHao @ 2019-07-28 11:22:31

#include <iostream>
using namespace std;
int a, b[100], c[100], k = 0, l;
char  h,m;
int re(int x)
{
    x = x - 26;
    if (x > 122)
    {
        re(x);
    }
    return x;
}
int main()
{
    scanf("%d", &a);
    m=getchar();
    for (int i = 97; i <= 122; i++)
    {
        b[k] = i;
        k++;
    }
    k = 0;
    while (1)
    {
        h = getchar();
        if (h == '\n')
            break;
        l = h  + a;
        if (l > 122)
        {
            l=re(l);
        }
        printf("%c",l);

    }

    return 0;
}

by JianZhiHao @ 2019-07-28 11:23:05

@JianZhiHao 源码在此,谢谢!


by 人间失格 @ 2019-07-28 11:30:36

@JianZhiHao 应该是读入一行字符串,把每个字母转换成int后+N%26再转换成字符串吧


by JianZhiHao @ 2019-07-28 12:01:52

@人间失格 解决了 thanks!


by 人间失格 @ 2019-07-28 12:29:07

@JianZhiHao 不用谢


|