您的位置:首页 > 其它

HDU-2816 I Love You Too

2011-08-29 12:49 239 查看

I Love You Too

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 865 Accepted Submission(s): 531


[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
A number string each line(length <= 1000). I ensure all input are legal.

[align=left]Output[/align]
An upper alphabet string.

[align=left]Sample Input[/align]

4194418141634192622374
41944181416341926223

[align=left]Sample Output[/align]

ILOVEYOUTOO
VOYEUOOTIO

  该题算是一个模拟题了,题目不难,这里用了map来直接映射。
  

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <map>
using namespace std;

char s[1005];

int rec[505], word[505];

int main()
{
map< int, char >mp;
mp[21] = 'K', mp[22] = 'X', mp[23] = 'V';
mp[31] = 'M', mp[32] = 'C', mp[33] = 'N';
mp[41] = 'O', mp[42] = 'P', mp[43] = 'H';
mp[51] = 'Q', mp[52] = 'R', mp[53] = 'S';
mp[61] = 'Z', mp[62] = 'Y', mp[63] = 'I';
mp[71] = 'J', mp[72] = 'A', mp[73] = 'D', mp[74] = 'L';
mp[81] = 'E', mp[82] = 'G', mp[83] ='W';
mp[91] = 'B', mp[92] = 'U', mp[93] = 'F', mp[94] = 'T';
while( scanf( "%s", s ) != EOF )
{
int len = strlen( s ), cnt = 0;
memset( rec, 0, sizeof( rec ) );
for( int i = 0; i < len; i += 2, ++cnt )
{
rec[cnt] += s[i] - '0';
rec[cnt] = rec[cnt] * 10 + s[i+1] - '0';
}
int lim = ( cnt - 1 ) >> 1;
for( int i = lim, j = cnt - 1, k = 0; i >= 0; --i, --j, k += 2 )
{
if( cnt & 1 )
{
word[k] = rec[i];
if( j > lim )
word[k+1] = rec[j];
}
else
{
word[k] = rec[j], word[k+1] = rec[i];
}
}
for( int i = 0; i < cnt; ++i )
{
printf( "%c", mp[word[i]] );
}
puts( "" );
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: