首页 > 代码库 > B - Encoded Love-letter 字符串的处理

B - Encoded Love-letter 字符串的处理

B - Encoded Love-letter
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1591

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
 
 
 1 #include<cstdio> 2 #include<string.h> 3 using namespace std; 4 char f[30]="1ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 5 char f1[100]; 6 int ff[100]; 7 char str[100]; 8 char s[1000]; 9 int main()10 {11     int i,j;12     int len;13     scanf("%s",str);14    //puts(str);15    getchar();16     len=strlen(str);17     memset(ff,0,sizeof(ff));18     memset(f1,0,sizeof(f1));19     for(i=1; i<=len; i++)20     {21         f1[i]=str[i-1];22         ff[str[i-1]-A+1]=1;23         //printf("%d ",ff[str[i-1]-‘A‘+1]);24     }25     j=i;26     for(i=26; i>=1; i--)27         if(ff[i]==0)28         {29              f1[j++]=A-1+i;30              //printf("%c ",f1[j-1]);31         }32     //printf("%s",f1);33     while(gets(s))34     {35        len=strlen(s);36        for(i=0;i<len;i++)37        {38            if(s[i]>=A&&s[i]<=Z)39            {40                for(j=1;j<=26;j++)41                   if(s[i]==f1[j]) printf("%c",f[j]);42            }43 44            else if(s[i]>=a&&s[i]<=z)45            {46                 for(j=1;j<=26;j++)47                    if(s[i]-a+A==f1[j]) printf("%c",f[j]-A+a);48            }49 50            //else if(s[i]==0) printf("\n");51            else printf("%c",s[i]);52        }53        printf("\n");54     }55 56     return 0;57 }