hdu---1591Encoded Love-letter

来源:互联网 发布:专业淘宝拍摄 编辑:程序博客网 时间:2024/05/01 13:21

Encoded Love-letter

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


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
 
 
 
 
//水题一枚,贴这个题主要是学习一下字符串的读入方式;  以及当段落之间输入有空行时,怎么处理。
// 这里是用的  判断 strlen(str) 是否为 0  来进行的判断。
// 读入含有空格的字符串这里使用的是 gets(str); 
代码:
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#define N 30char f[N]={"1ABCDEFGHIJKLMNOPQRSTUVWXYZ "},f1[N];char str[N];int ff[N];char s[1000];int main(){    int i,j,k=0;    freopen("in.txt","r",stdin);    scanf("%s",str);getchar();        //for(i=0;i<N;i++) ff[i]=0;        int len=strlen(str);        for(i=1;i<=len;i++){            f1[i]=str[i-1];            ff[str[i-1]-'A'+1]=1;        }        j=i;        for(i=26;i>=1;i--)            if(ff[i]==0)                f1[j++]='A'-1+i;        char x=' ';        //得到转换的字符数组。    while(gets(s)){        len=strlen(s);        if(len==0) printf("\n");        else{            for(i=0;i<len;i++){                for(j=1;j<=26;j++)                    if(s[i]==f1[j] || s[i]==f1[j]-'A'+'a')                        break;                if(j==27)                    printf("%c",s[i]);                else if(s[i]>='a' && s[i]<='z')                    printf("%c",f[j]-'A'+'a');                else printf("%c",f[j]);            }            printf("\n");        }    }    return 0;}

 

0 0
原创粉丝点击