zoukankan      html  css  js  c++  java
  • HDU2816 I Love You Too

    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


    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
     
      该题算是一个模拟题了,题目不难,这里用了map来直接映射。
      
     1 #include <cstring>
    2 #include <cstdlib>
    3 #include <cstdio>
    4 #include <map>
    5 using namespace std;
    6
    7 char s[1005];
    8
    9 int rec[505], word[505];
    10
    11 int main()
    12 {
    13 map< int, char >mp;
    14 mp[21] = 'K', mp[22] = 'X', mp[23] = 'V';
    15 mp[31] = 'M', mp[32] = 'C', mp[33] = 'N';
    16 mp[41] = 'O', mp[42] = 'P', mp[43] = 'H';
    17 mp[51] = 'Q', mp[52] = 'R', mp[53] = 'S';
    18 mp[61] = 'Z', mp[62] = 'Y', mp[63] = 'I';
    19 mp[71] = 'J', mp[72] = 'A', mp[73] = 'D', mp[74] = 'L';
    20 mp[81] = 'E', mp[82] = 'G', mp[83] ='W';
    21 mp[91] = 'B', mp[92] = 'U', mp[93] = 'F', mp[94] = 'T';
    22 while( scanf( "%s", s ) != EOF )
    23 {
    24 int len = strlen( s ), cnt = 0;
    25 memset( rec, 0, sizeof( rec ) );
    26 for( int i = 0; i < len; i += 2, ++cnt )
    27 {
    28 rec[cnt] += s[i] - '0';
    29 rec[cnt] = rec[cnt] * 10 + s[i+1] - '0';
    30 }
    31 int lim = ( cnt - 1 ) >> 1;
    32 for( int i = lim, j = cnt - 1, k = 0; i >= 0; --i, --j, k += 2 )
    33 {
    34 if( cnt & 1 )
    35 {
    36 word[k] = rec[i];
    37 if( j > lim )
    38 word[k+1] = rec[j];
    39 }
    40 else
    41 {
    42 word[k] = rec[j], word[k+1] = rec[i];
    43 }
    44 }
    45 for( int i = 0; i < cnt; ++i )
    46 {
    47 printf( "%c", mp[word[i]] );
    48 }
    49 puts( "" );
    50 }
    51 return 0;
    52 }

      

  • 相关阅读:
    图像滤镜艺术---乐高像素拼图特效滤镜的代码实现
    假设你也23
    seajs载入流程图
    android 怎样将主菜单图标改成按安装时间排序
    热力学第一定律的社会学思考
    Django创建数据表
    KeyPress 和KeyDown 、KeyPress之间的区别
    Delphi 制作自定义数据感知控件并装入包(dpk文件)中(与DBText类似的数据感知控件)
    Delphi中的窗体创建与销毁
    Delphi ADOQuery连接数据库的查询、插入、删除、修改
  • 原文地址:https://www.cnblogs.com/Lyush/p/2158068.html
Copyright © 2011-2022 走看看