Processing of B-encoded love-letter strings

Source: Internet
Author: User
B-encoded love-letter Time limit:1000 ms Memory limit:32768kb 64bit Io format:% I64d & % i64usubmit 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 %xahl %%%sl atfack jxwru w eqr 'J Farra %%%aj jxl eaccqi AML atfack qr SC %w vikj Gar jxwru anqij cqiwz jxl EAC WR jxl please refer to fwtt when jmilw 'hl when gxaryl SC swre jxaj W fwtt tqhl CQI when EQR 'J gaml when zqqt WJ wkw fwtt tlj SC emlas when jmilw then jltt CQI when w Farra TLJ CQI?, w tlj cqi urrentw 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 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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.