B - Encoded Love-letter 字符串的处理
2014-08-03 11:08
204 查看
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
ANGEL
Fxlr jxaj eac W xlam cqim hqwgl
W xahl kqsl kplgwat zlltwry
Tlj sl atfack jxwru W eqr'j farra zqmylj cqi
W mlslsnlm aj jxl eac
Cqi aml atfack qr sc swre
Lhlrjxqiyx W vikj gar jxwru anqij cqi
Wz jxl eac wr jxl zijiml
Jxwk tqhl fwtt nlgqswry jmil
W'hl rlhlm gxaryl sc swre jxaj W fwtt tqhl cqi zqmlhlm
W eqr'j gaml xqf zqqt wj wk
W fwtt tlj sc emlas gqsl jmil
W fwtt jltt cqi kqsljxwry W farra tlj cqi urqf, W tlj cqi urqf
W tqhl cqi, tqhwry cqi, ak jxl sqikl tqhlk jxl mwgl
Lhlr lhlmc eac xak kjqms, W fwtt atfack nc cqim kwel
W swkk cqi, swkkwry cqi
W eqr'j gaml xqf xame wj wk
W vikj farj cqi jq nl xappc
Lhlmcjxwry, W eq wj zqm cqi
Sample Output
When that day I hear your voice
I have some special feeling
Let me always think I don't wanna forget you
I remember at the day
You are always on my mind
Eventhough I just can think about you
If the day in the future
This love will becoming true
I've never change my mind that I will love you forever
I don't care how fool it is
I will let my dream come true
I will tell you something I wanna let you know, I let you know
I love you, loving you, as the mouse loves the rice
Even every day has storm, I will always by your side
I miss you, missing you
I don't care how hard it is
I just want you to be happy
Everything, I do it for you
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
ANGEL
Fxlr jxaj eac W xlam cqim hqwgl
W xahl kqsl kplgwat zlltwry
Tlj sl atfack jxwru W eqr'j farra zqmylj cqi
W mlslsnlm aj jxl eac
Cqi aml atfack qr sc swre
Lhlrjxqiyx W vikj gar jxwru anqij cqi
Wz jxl eac wr jxl zijiml
Jxwk tqhl fwtt nlgqswry jmil
W'hl rlhlm gxaryl sc swre jxaj W fwtt tqhl cqi zqmlhlm
W eqr'j gaml xqf zqqt wj wk
W fwtt tlj sc emlas gqsl jmil
W fwtt jltt cqi kqsljxwry W farra tlj cqi urqf, W tlj cqi urqf
W tqhl cqi, tqhwry cqi, ak jxl sqikl tqhlk jxl mwgl
Lhlr lhlmc eac xak kjqms, W fwtt atfack nc cqim kwel
W swkk cqi, swkkwry cqi
W eqr'j gaml xqf xame wj wk
W vikj farj cqi jq nl xappc
Lhlmcjxwry, W eq wj zqm cqi
Sample Output
When that day I hear your voice
I have some special feeling
Let me always think I don't wanna forget you
I remember at the day
You are always on my mind
Eventhough I just can think about you
If the day in the future
This love will becoming true
I've never change my mind that I will love you forever
I don't care how fool it is
I will let my dream come true
I will tell you something I wanna let you know, I let you know
I love you, loving you, as the mouse loves the rice
Even every day has storm, I will always by your side
I miss you, missing you
I don't care how hard it is
I just want you to be happy
Everything, I do it for you
#include<cstdio> #include<string.h> using namespace std; char f[30]="1ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char f1[100]; int ff[100]; char str[100]; char s[1000]; int main() { int i,j; int len; scanf("%s",str); //puts(str); getchar(); len=strlen(str); memset(ff,0,sizeof(ff)); memset(f1,0,sizeof(f1)); for(i=1; i<=len; i++) { f1[i]=str[i-1]; ff[str[i-1]-'A'+1]=1; //printf("%d ",ff[str[i-1]-'A'+1]); } j=i; for(i=26; i>=1; i--) if(ff[i]==0) { f1[j++]='A'-1+i; //printf("%c ",f1[j-1]); } //printf("%s",f1); while(gets(s)) { len=strlen(s); for(i=0;i<len;i++) { if(s[i]>='A'&&s[i]<='Z') { for(j=1;j<=26;j++) if(s[i]==f1[j]) printf("%c",f[j]); } else if(s[i]>='a'&&s[i]<='z') { for(j=1;j<=26;j++) if(s[i]-'a'+'A'==f1[j]) printf("%c",f[j]-'A'+'a'); } //else if(s[i]==0) printf("\n"); else printf("%c",s[i]); } printf("\n"); } return 0; }
相关文章推荐
- HDU 1591 Encoded Love-letter(简单字符串)
- HDU1591-Encoded Love-letter
- Encoded Love-letter
- WOJ1141-Encoded Love-letter
- hdu---1591Encoded Love-letter
- hdu 5082 Love(字符串处理)
- 模拟字符串处理函数 stuff 的存储过程,对 ntext 字段进行stuff
- VB中字符串处理函数反汇编对比
- 几个字符串处理方法:
- ASP中一个字符串处理类加强版
- JAVA-字符串处理中的重点
- 改进 ASP 的字符串处理性能
- clob相关的咚咚以及字符串处理
- 改进 ASP 应用程序中的字符串处理性能[转帖]
- SQL字符串日期处理.doc
- 触发器实现字符串处理及统计
- 字段里字符串的处理问题
- 改进 ASP 应用程序中的字符串处理性能
- 几个非常有用的字符串处理函数!
- javascript字符串处理