HDU 2816 I Love You Too
I Love You Too
Problem Description
This is a true story. A man showed his love to a girl,but the girl didn't replied clearly ,just gave him a Morse Code:
****-/*----/----*/****-/****-/*----/---**/*----/****-/*----/-****/***--/****-/*----/----*/**---/-****/**---/**---/***--/--***/****-/ He was so anxious that he asked for help in the Internet and after one day a girl named "Pianyi angel" found the secret of this code. She translate this code as this five steps:
1.First translate the morse code to a number string:4194418141634192622374
2.Second she cut two number as one group 41 94 41 81 41 63 41 92 62 23 74,according to standard Mobile phone can get this alphabet:GZGTGOGXNCS
3.Third she change this alphabet according to the keyboard:QWERTYUIOPASDFGHJKLZXCVBNM = ABCDEFGHIJKLMNOPQRSTUVWXYZ
So ,we can get OTOEOIOUYVL
4.Fourth, divide this alphabet to two parts: OTOEOI and OUYVL, compose again.we will get OOTUOYEVOLI
5.Finally,reverse this alphabet the answer will appear : I LOVE YOU TOO
I guess you might worship Pianyi angel as me,so let's Orz her.
Now,the task is translate the number strings.
****-/*----/----*/****-/****-/*----/---**/*----/****-/*----/-****/***--/****-/*----/----*/**---/-****/**---/**---/***--/--***/****-/ He was so anxious that he asked for help in the Internet and after one day a girl named "Pianyi angel" found the secret of this code. She translate this code as this five steps:
1.First translate the morse code to a number string:4194418141634192622374
2.Second she cut two number as one group 41 94 41 81 41 63 41 92 62 23 74,according to standard Mobile phone can get this alphabet:GZGTGOGXNCS
3.Third she change this alphabet according to the keyboard:QWERTYUIOPASDFGHJKLZXCVBNM = ABCDEFGHIJKLMNOPQRSTUVWXYZ
So ,we can get OTOEOIOUYVL
4.Fourth, divide this alphabet to two parts: OTOEOI and OUYVL, compose again.we will get OOTUOYEVOLI
5.Finally,reverse this alphabet the answer will appear : I LOVE YOU TOO
I guess you might worship Pianyi angel as me,so let's Orz her.
Now,the task is translate the number strings.
Input
A number string each line(length <= 1000). I ensure all input are legal.
Output
An upper alphabet string.
Sample Input
4194418141634192622374
41944181416341926223
Sample Output
ILOVEYOUTOO
VOYEUOOTIO
代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 using namespace std; 5 6 char key1[9][5]={" ","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"}; 7 char key2[28]={" QWERTYUIOPASDFGHJKLZXCVBNM"}; 8 9 int main() 10 { 11 int i,j,k,t; 12 char s[1005]; 13 char temp[1005]; 14 char ans[1005]; 15 while(scanf("%s",s)!=EOF) 16 { 17 int len=strlen(s); 18 for(j=0,i=0;i<len;i+=2) 19 temp[j++]=key1[s[i]-'0'-1][s[i+1]-'0'-1]; 20 temp[j]='\0'; 21 t=0; 22 for(i=0;i<j;i++) 23 { 24 for(k=1;k<27;k++) 25 if(temp[i]==key2[k]) 26 ans[t++]=(char)(k+'A'-1); 27 } 28 ans[t]='\0'; 29 for(j=0,i=ceil((double)t/2);i<t;i++) 30 temp[j++]=ans[i]; 31 temp[j]='\0'; 32 for(i=ceil((double)t/2)-1;i>0;i--) 33 ans[i*2]=ans[i]; 34 for(j=0,i=1;i<t;i+=2) 35 ans[i]=temp[j++]; 36 ans[t]=='\0'; 37 strrev(ans); 38 printf("%s\n",ans); 39 } 40 return 0; 41 }