WOJ1141-Encoded Love-letter
2017-09-04 20:37
323 查看
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?
chara
4000
ctor will be decoded to a lower-case charactor.
按照置换的方法套回去就可以
#include<stdio.h>
#include<string.h>
char key[27];
int decode[26];
int letter[26];
char c;
int main(){
scanf("%s",&key);
int i,l=strlen(key),t;
memset(letter,0,sizeof(letter));
for(i=0;i<l;i++){
t=key[i]-'A';
letter[t]=1;
decode[i]=t;
}
t=26;
for(;i<26;i++){
while(t--){
if(letter[t]==0)
break;
}
decode[i]=t;
}
for(i=0;i<26;i++){
letter[decode[i]]=i;
}
/*for(i=0;i<26;i++){
printf("%c",'A'+decode[i]);
}*/
getchar();
while(scanf("%c",&c)!=EOF){
if(c>='a'&&c<='z')
printf("%c",'a'+letter[c-'a']);
else if(c>='A'&&c<='Z')
printf("%c",'A'+letter[c-'A']);
else
printf("%c",c);
}
return 0;
}
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?
输入格式
The letter will begin with the keyword (All uppercase), then lines of text.输出格式
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-casechara
4000
ctor will be decoded to a lower-case charactor.
样例输入
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
样例输出
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<stdio.h>
#include<string.h>
char key[27];
int decode[26];
int letter[26];
char c;
int main(){
scanf("%s",&key);
int i,l=strlen(key),t;
memset(letter,0,sizeof(letter));
for(i=0;i<l;i++){
t=key[i]-'A';
letter[t]=1;
decode[i]=t;
}
t=26;
for(;i<26;i++){
while(t--){
if(letter[t]==0)
break;
}
decode[i]=t;
}
for(i=0;i<26;i++){
letter[decode[i]]=i;
}
/*for(i=0;i<26;i++){
printf("%c",'A'+decode[i]);
}*/
getchar();
while(scanf("%c",&c)!=EOF){
if(c>='a'&&c<='z')
printf("%c",'a'+letter[c-'a']);
else if(c>='A'&&c<='Z')
printf("%c",'A'+letter[c-'A']);
else
printf("%c",c);
}
return 0;
}
相关文章推荐
- HDU 1591 Encoded Love-letter(简单字符串)
- B - Encoded Love-letter 字符串的处理
- HDU1591-Encoded Love-letter
- Encoded Love-letter
- hdu---1591Encoded Love-letter
- 杭电1591 hdu 1591 Encoded Love-letter
- 一封绝妙的情书 An Ingenious Love Letter
- HDU 1591 Encoded Love-letter
- A Love Letter To Josephine
- 湘潭大学校赛A Love Letter
- ACM--模拟--湘大OJ 1184--A Love Letter--水
- 一封绝妙的情书 An Ingenious Love Letter
- A Love Letter For You
- A Love Letter
- 第八届湘潭大学程序设计比赛 A Love Letter
- A Love Letter
- A Love Letter
- Still in Love with C++ 中文版(1)
- Love is Blue
- The Look of Love