HDU1591 Encoded Love-letter密码

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU1591 Encoded Love-letter密码相关的知识,希望对你有一定的参考价值。

Encoded Love-letter
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1998 Accepted Submission(s): 751

Problem Description
After Gardon had got Angel’s letter, he found it was encoded…Oh my god, why did she encode a love-letter?? But don’t worry, she wrote the algorithm for encoding after the letter:
Each charactor are changed to a corresponding charactor. If the keyword is “Angel”, the rule will be:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
ANGELZYXWVUTSRQPOMKJIHFDCB

You may find that in the bottom line, charactors of the keyword come first. All other charactors will come in a reversed order.

Now given another keyword, work the letter out!
Can you write a program to translate the letter?

Input
The letter will begin with the keyword (All uppercase), then lines of text.

Output
Decode the letter and print it out. Please note that a upper-case charactor will be decoded to a upper-case charactor, while a lower-case charactor will be decoded to a lower-case charactor.

Sample Input
ANGEL
Fxlr jxaj eac W xlam cqim hqwgl
W xahl kqsl kplgwat zlltwry
Tlj sl atfack jxwru W eqr’j farra zqmylj cqi
W mlslsnlm aj jxl eac
Cqi aml atfack qr sc swre
Lhlrjxqiyx W vikj gar jxwru anqij cqi
Wz jxl eac wr jxl zijiml
Jxwk tqhl fwtt nlgqswry jmil
W’hl rlhlm gxaryl sc swre jxaj W fwtt tqhl cqi zqmlhlm
W eqr’j gaml xqf zqqt wj wk
W fwtt tlj sc emlas gqsl jmil
W fwtt jltt cqi kqsljxwry W farra tlj cqi urqf, W tlj cqi urqf

W tqhl cqi, tqhwry cqi, ak jxl sqikl tqhlk jxl mwgl
Lhlr lhlmc eac xak kjqms, W fwtt atfack nc cqim kwel
W swkk cqi, swkkwry cqi
W eqr’j gaml xqf xame wj wk
W vikj farj cqi jq nl xappc
Lhlmcjxwry, W eq wj zqm cqi

Sample Output
When that day I hear your voice
I have some special feeling
Let me always think I don’t wanna forget you
I remember at the day
You are always on my mind
Eventhough I just can think about you
If the day in the future
This love will becoming true
I’ve never change my mind that I will love you forever
I don’t care how fool it is
I will let my dream come true
I will tell you something I wanna let you know, I let you know

I love you, loving you, as the mouse loves the rice
Even every day has storm, I will always by your side
I miss you, missing you
I don’t care how hard it is
I just want you to be happy
Everything, I do it for you

Author
DYGG

Source
HDU “Valentines Day” Open Programming Contest 2007-02-14

问题链接HDU1591 Encoded Love-letter
问题简述:(略)
问题分析:密码问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* HDU1591 Encoded Love-letter */

#include <bits/stdc++.h>

using namespace std;

const int L = 'Z' - 'A' + 1;
char w[L + 1], f[L + 1];

int main()
{
    scanf("%s", w);
    getchar();

    for (int i = 0; w[i]; i++)
        if (islower(w[i])) w[i] -= 32;
    strcpy(f, w);
    int k = L - 1, len = strlen(w);
    for (int i = L - 1, j; i >= 0; i--) {
        for (j = 0; w[j]; j++)
            if ('Z' - i == w[j]) break;
        if (j == len) f[k--] = 'Z' - i;
    }

    char c;
    while ((c = getchar()) != EOF) {
        if (isalpha(c)) {
            for (int i = 0; i < L; i++)
                if (c == f[i] || c == f[i] + 32) {
                    putchar(isupper(c) ? 'A' + i : 'a' + i);
                    break;
                }
        } else
            putchar(c);
    }

    return 0;
}

以上是关于HDU1591 Encoded Love-letter密码的主要内容,如果未能解决你的问题,请参考以下文章

HDU 3724 Encoded Barcodes (Trie)

hdu 1584 dfs+剪枝

HDU 6128-数论

如何在 Visual Studio Mac for Unity 解决方案中避免 CS1591 警告?

洛谷——P1591 阶乘数码

洛谷 P1591 阶乘数码