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.
4194418141634192622374
41944181416341926223
ILOVEYOUTOO
VOYEUOOTIO
题意:给出一串长度不大于1000的数字,按每两个数字对应一个字母来解密(如图,即手机按键上的字母,如22代表B),解密后在根据解密对应的编码【3】来得到字母串,然后拆成两半(前部分不短于后部分),再按照【4】重新得到字母串,最后反序输出该字母串就ok啦。(貌似此密码很让人头疼呀。。。。别急,一步一步来,题目并不难)
#include<iostream> using namespace std; int main() { char a[1010]; char b[505]; char c[252]; char d[252]; char ans[505]; char x[8][5]={"KXV","MCN","OPH","QRS","ZYI","JADL","EGW","BUFT"}; //已经按照密码定义了 while(scanf("%s",a)!=EOF) { int i,j,k; for(i=0,j=0;i<strlen(a);i+=2,j++) { a[i]-='0'; //把字符转化为数字 a[i+1]-='0'; b[j]=x[a[i]-2][a[i+1]-1]; //求出每两个数字对应的一个字母 } //要把字母串分成两个部分,而且前部分不短于后部分 for(i=0;i<((strlen(a)/2)+1)/2;i++) c[i]=b[i]; for(j=i,k=0;j<strlen(a)/2;j++,k++) d[k]=b[j]; j=0;k=0; //再把两个字母串合并 for(i=0;i<strlen(a)/2;i++) { if((i+1)%2!=0) ans[i]=c[j++]; else ans[i]=d[k++]; } for(i=strlen(a)/2-1;i>=0;i--) printf("%c",ans[i]); printf("\n"); } return 0; }