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.
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
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
const int M=1005;
char zh1[27]={"QWERTYUIOPASDFGHJKLZXCVBNM"};
char zh2[27]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
char num[10][5]={"","_","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
int main()
{
char str[M];
char c[505];
char ans[M];
char zh[M];
while(gets(str))
{
int L1;
int t=0;
int len=strlen(str);
for(int i=0;i<len;i+=2)
{
c[t++]=num[str[i]-'0'][str[i+1]-'0'-1];
}
len=t;
c[len]='\0';
for(int i=0;i<len;i++)
{
for(int j=0;j<27;j++)
{
if(c[i]==zh1[j])
{
c[i]=zh2[j];
break;
}
}
}
int i,j;
if(len%2!=0)
L1=len/2+1;
else
L1=len/2;
int k=0;
for(i=0,j=L1;i<L1&&j<len;i++,j++)
{
ans[k++]=c[i];
ans[k++]=c[j];
}
for(;i<L1;i++)
ans[k++]=c[i];
for(;j<len;j++)
ans[k++]=c[j];
for(i=k-1;i>=0;i--)
putchar(ans[i]);
cout<<endl;
}
return 0;
}