E - I Love You Too解题报告(张宇)

来源:互联网 发布:淘宝纸盒加工厂前景 编辑:程序博客网 时间:2024/05/16 19:57

E - I Love You Too
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 2816

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

419441814163419262237441944181416341926223
 

Sample Output

ILOVEYOUTOOVOYEUOOTIO
 

题意:给出一串长度不大于1000的数字,按每两个数字对应一个字母来解密(如图,即手机按键上的字母,如22代表B),解密后在根据解密对应的编码【3】来得到字母串,然后拆成两半(前部分不短于后部分),再按照【4】重新得到字母串,最后反序输出该字母串就ok啦。(貌似此密码很让人头疼呀。。。。别急,一步一步来,题目并不难)

[cpp] view plaincopy
  1. #include<iostream>  
  2. using namespace std;  
  3. int main()  
  4. {  
  5.     char a[1010];  
  6.     char b[505];  
  7.     char c[252];  
  8.     char d[252];  
  9.     char ans[505];  
  10.     char x[8][5]={"KXV","MCN","OPH","QRS","ZYI","JADL","EGW","BUFT"}; //已经按照密码定义了  
  11.     while(scanf("%s",a)!=EOF)  
  12.     {  
  13.         int i,j,k;  
  14.         for(i=0,j=0;i<strlen(a);i+=2,j++)  
  15.         {     
  16.             a[i]-='0';            //把字符转化为数字  
  17.             a[i+1]-='0';  
  18.             b[j]=x[a[i]-2][a[i+1]-1];   //求出每两个数字对应的一个字母  
  19.         }  
  20.         //要把字母串分成两个部分,而且前部分不短于后部分  
  21.         for(i=0;i<((strlen(a)/2)+1)/2;i++)  
  22.             c[i]=b[i];  
  23.         for(j=i,k=0;j<strlen(a)/2;j++,k++)  
  24.             d[k]=b[j];  
  25.         j=0;k=0;  
  26.         //再把两个字母串合并  
  27.         for(i=0;i<strlen(a)/2;i++)  
  28.         {  
  29.             if((i+1)%2!=0)  
  30.                 ans[i]=c[j++];  
  31.             else  
  32.                 ans[i]=d[k++];  
  33.         }  
  34.         for(i=strlen(a)/2-1;i>=0;i--)  
  35.             printf("%c",ans[i]);  
  36.         printf("\n");  
  37.     }  
  38.     return 0;  
  39. }  



原创粉丝点击