C++:HDU1591 Encoded Love-letter

Encoded Love-letter

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1883    Accepted Submission(s): 697


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
 
 
ANGELFxlr jxaj eac W xlam cqim hqwglW xahl kqsl kplgwat zlltwryTlj sl atfack jxwru W eqr'j farra zqmylj cqiW mlslsnlm aj jxl eacCqi aml atfack qr sc swreLhlrjxqiyx W vikj gar jxwru anqij cqiWz jxl eac wr jxl zijimlJxwk tqhl fwtt nlgqswry jmilW'hl rlhlm gxaryl sc swre jxaj W fwtt tqhl cqi zqmlhlmW eqr'j gaml xqf zqqt wj wkW fwtt tlj sc emlas gqsl jmilW fwtt jltt cqi kqsljxwry W farra tlj cqi urqf, W tlj cqi urqfW tqhl cqi, tqhwry cqi, ak jxl sqikl tqhlk jxl mwglLhlr lhlmc eac xak kjqms, W fwtt atfack nc cqim kwelW swkk cqi, swkkwry cqiW eqr'j gaml xqf xame wj wkW vikj farj cqi jq nl xappcLhlmcjxwry, W eq wj zqm cqi
 

Sample Output
 
 
When that day I hear your voiceI have some special feelingLet me always think I don't wanna forget youI remember at the dayYou are always on my mindEventhough I just can think about youIf the day in the futureThis love will becoming trueI've never change my mind that I will love you foreverI don't care how fool it isI will let my dream come trueI will tell you something I wanna let you know, I let you knowI love you, loving you, as the mouse loves the riceEven every day has storm, I will always by your sideI miss you, missing youI don't care how hard it isI just want you to be happyEverything, I do it for you
 

Author
DYGG
 

Source

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


解题思路:题意就是先输入一串字符,表示26个英文字母对应的密码表的前几个是这串字符,另外的字符倒序存入,例如:

     输入:ANGEL   ,那么对应关系就是

     ABCDEFGHIJKLMNOPQRSTUVWXYZ

           ANGELZYXWVUTSRQPOMKJIHFDCB

     输入:BCD  ,那么对应关系就是

     ABCDEFGHIJKLMNOPQRSTUVWXYZ

     BCDZYXWVUTSRQPONMLKJIHGFEA

然后对照关系表输出即可。


代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[100],st[100];
    scanf("%s",st);
    getchar();//吞掉回车
    int l=strlen(st);
    for(int i=l,j=90;j>=65;i++,j--)
    {
        st[i]=j;
        for(int k=0;k<l;k++)
        {
            if(st[i]==st[k])
            {
                i--;
                break;
            }
        }
    }//循环结束后,st数组内存的就是对应的字母并且全部是大写
    strcpy(s,st);//把st数组存入s数组
    strlwr(s);//把s数组全部转化为小写字母
    char a;
    while(~scanf("%c",&a))
    {
        if(a>='a'&&a<='z')
        {
            for(int i=0;i<26;i++)
            {
                if(a==s[i])
                {
                    printf("%c",97+i);
                }
            }
        }
        else if(a>='A'&&a<='Z')
        {
            for(int i=0;i<26;i++)
            {
                if(a==st[i])
                {
                    printf("%c",65+i);
                }
            }
        }
        else
            printf("%c",a);
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值