hrbust 哈理工oj 1330 邂逅【模拟】

邂逅
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 326(218 users) Total Accepted: 235(211 users) Rating:  Special Judge: No
Description

ACM集训队纳新了,GG忙着面试前来应招的各位同学,这时来了MM。GG找了个有趣的问题让MM来解决——解密字符串。首先GG递给MM一张纸,纸上边写了一些数字,这些每2个相邻且不为0的数字为一组代表一个字母,它们刚好与手机按键相对应。手机按键的1-9中,1上无字母,2号键上为abc,3号键上为def,4号键上为ghi,5号键上为jkl,6号键上为mno,7号键上为pqrs,8号键上为tuv,9号为wxyz。我们规定用0表示空格。

一组中的第一个数字就代表是哪个数字键,第二个数字代表这个键上的第几个字母,比如23代表的就是字母c。

现在请你帮MM写个程序完成这个任务。
Input

输入数据有多组,对于每一组测试数据,有一行长度不超过1000的数字串,由0-9数字组成。注意0表示一个空格。

Output

对于每组测试数据,输出一行解密后的字符串并换行。它仅包含小写字母和空格,代表解密后的结果。

Sample Input
430536383320212361
430912162810816304132810216202123233271813231
Sample Output
i love acm
i want to get an accepted
Source
2012 Spring Contest 5 - Binary Search, Greedy, DP

根据题目要求模拟,我们最初用map【i】【j】二维数组表示第i个键子上边第j个字母。

AC代码:

#include<stdio.h>
#include<string.h>
using namespace std;
char map[9][4];
char a[121212];
int main()
{
    map[2][0]='a';map[2][1]='b';map[2][2]='c';
    map[3][0]='d';map[3][1]='e';map[3][2]='f';
    map[4][0]='g';map[4][1]='h';map[4][2]='i';
    map[5][0]='j';map[5][1]='k';map[5][2]='l';
    map[6][0]='m';map[6][1]='n';map[6][2]='o';
    map[7][0]='p';map[7][1]='q';map[7][2]='r';map[7][3]='s';
    map[8][0]='t';map[8][1]='u';map[8][2]='v';
    map[9][0]='w';map[9][1]='x';map[9][2]='y';map[9][3]='z';
    while(~scanf("%s",a))
    {
        for(int i=0;i<strlen(a);i++)
        {
            if(a[i]=='0'){printf(" ");continue;}
            if(a[i]=='1')continue;
            else
            {
                int id=a[i]-'0';
                i++;
                int id2=a[i]-'0';
               // printf("%d %d\n",id,id2);
                id2--;
                printf("%c",map[id][id2]);
            }
        }
        printf("\n");
    }
}







你可能感兴趣的:(1330,哈理工oj,hrbust)