HDU 1591 Encoded Love-letter(簡單字串)

來源:互聯網
上載者:User

標籤:sample   div   ack   qml   lines   jxl   getchar   please   hdu   

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


Problem DescriptionAfter 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? 

 

InputThe letter will begin with the keyword (All uppercase), then lines of text. 

 

OutputDecode 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 InputANGELFxlr 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 urqf W 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 OutputWhen 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 know I 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 is I just want you to be happyEverything, I do it for you

 

 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 char sh[1100],s[1100]; 6 char c; 7 int i,j,k,l,m,n; 8 void ac(char sh[]) 9 {10     l=strlen(sh);11     for(i=0;i<l;i++)12     if(sh[i]>=‘a‘&&sh[i]<=‘z‘)13     sh[i]-=32;//先變成大寫 14     for(i=0;i<l;i++)15     s[i]=sh[i];16     int flag=25;17     for(i=25;i>=0;i--)//得到密碼字串 18     {19         for(j=0;j<l;j++)20         if(‘Z‘-i==sh[j])21         break;22         if(j==l)23         s[flag--]=‘Z‘-i;24     }25 }26 int main()27 {28     scanf("%s",sh);29     getchar();30     ac(sh);31     while(scanf("%c",&c)!=EOF)//逐個字母輸入 32     {33         for(i=0;i<26;i++)34         {35             if(c==s[i])36             {37                 printf("%c",‘A‘+i);38                 break;39             }40             41             if(c==s[i]+32)42             {43                 printf("%c",‘a‘+i);44                 break;45             }46         }47             if(i==26)48             printf("%c",c);49     }50 }

 

HDU 1591 Encoded Love-letter(簡單字串)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.