HDU-1591-Encoded Love-letter

Encoded Love-letter


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

题意:根据输入的字符进行编码,字符都是大写字符,在编码字符串中先是输入的字符串然后是没有出现的英文字母反序排列,下面输入文章,是根据编码字符串找对应正常字母字符串,(刚开始理解反了,比如例子以为是根据上面的找下面的,结果是根据下面的找上面的),推翻从来,然后思路就乱了,还好还是ac了。


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[100];
    int b[30];
    int k=0,l,flag;
    scanf("%s",a);
    getchar();
    l=strlen(a);
    memset(b,0,sizeof(b));
    for(int i=0;i<l;i++)
    {
       b[a[i]-'A']=i;
    }
    k=l;
    for(int i=25;i>=0;i--)
    {
        flag=0;
        for(int j=0;j<l;j++)
        {
            if(i==a[j]-'A')
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            b[i]=k++;
        }
    }
    char c;
    while(~scanf("%c",&c))
    {
        if(c>='a'&&c<='z')
        {
            printf("%c",b[c-'A'-32]+'a');
        }
        else
        if(c>='A'&&c<='Z')
        {
            printf("%c",b[c-'A']+'A');
        }
        else
        {
            printf("%c",c);
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值