HDU - 2816 I Love You Too(水)

来源:互联网 发布:淘宝的火麻叶是真的么 编辑:程序博客网 时间:2024/05/17 08:38
I Love You Too
Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u

Submit Status

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
 

水水的~~ ~~

敲代码的时候,时不时把重要的变量打印出来是一件很好的事情。

#include<iostream>using namespace std;const char dig[12][6] = { "0", "_", "0ABC", "0DEF", "0GHI", "0JKL", "0MNO", "0PQRS", "0TUV", "0WXYZ" };const char all[30] = "QWERTYUIOPASDFGHJKLZXCVBNM";int main(){char digi[1010];while (cin >> digi){char al[1010]="0";int len = strlen(digi);for (int i = 0; i < len/2; i++){al[i] = dig[digi[i * 2]-'0'][digi[i * 2 + 1]-'0'];}/*for (int i = 0; i < len / 2; i++)cout << al[i] << " ";cout << endl;*/for (int i = 0; i < len / 2; i++){for (int j = 0; j <= 26;j++)if (al[i] == all[j]){al[i] = 'A' + j; break;}}/*for (int i = 0; i < len / 2; i++)cout << al[i] << " ";cout << endl;*/char ans[1010];for (int i = 0; i < (len / 2+1)/2; i++){ans[i * 2] = al[i];}for (int i = (len / 2 + 1) / 2,j=0; i < len / 2; i++, j++){ans[j * 2+1] = al[i];}/*for (int i = 0; i < len / 2; i++)cout << ans[i] << " ";cout << endl;*/char ans2[1010] = { 0 };for (int i = 0; i < len / 2; i++)ans2[i] = ans[len / 2 - 1 - i];/*for (int i = 0; i < len / 2; i++)cout << ans2[i] << " ";cout << endl;*/ans2[len / 2] = '\0';cout << ans2 << endl;}}



0 0
原创粉丝点击