hdu 1982 Kaitou Kid - The Phantom Thief (1)

xiaoxiao2021-02-28  96

本题链接:点击打开链接

Kaitou Kid - The Phantom Thief (1)

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3120    Accepted Submission(s): 1396 Problem Description Do you know Kaitou Kid? In the legend, Kaitou Kid is a master of disguise, and can take on the voice and form of anyone. He is not an evil person, but he is on the wrong side of the law. He's the very elusive phantom thief who never miss his prey although he always uses word puzzles to announce his targets before action. You are the leader of a museum. Recently, you get several priceless jewels and plan to hold an exhibition. But at the moment, you receive Kid's word puzzle... Fortunately, It seems Kid doesn’t want to trouble you, and his puzzle is very easy. Just a few minutes, You have found the way to solve the puzzle: (1) change 1 to 'A', 2 TO 'B',..,26 TO 'Z' (2) change '#' to a blank (3) ignore the '-' symbol, it just used to separate the numbers in the puzzle   Input The first line of the input contains an integer C which means the number of test cases. Then C lines follow. Each line is a sentence of Kid’s word puzzle which is consisted of '0' ~ '9' , '-' and '#'. The length of each sentence is no longer than 10000.   Output For each case, output the translated text.   Sample Input 4 9#23-9-12-12#19-20-5-1-12#1-20#12-5-1-19-20#15-14-5#10-5-23-5-12 1-14-4#12-5-1-22-5#20-8-5#13-21-19-5-21-13#9-14#20#13-9-14-21-20-5-19 1-6-20-5-18#20-8-5#15-16-5-14-9-14-7#15-6#20-8-5#5-24-8-9-2-9-20-9-15-14 7-15-15-4#12-21-3-11   Sample Output I WILL STEAL AT LEAST ONE JEWEL AND LEAVE THE MUSEUM IN T MINUTES AFTER THE OPENING OF THE EXHIBITION GOOD LUCK   Author LL   Source 2008杭电集训队选拔赛   Recommend wangye   |   We have carefully selected several similar problems for you:  1984 1981 1256 1321 1328    大致题意: 先输入一个整数c,代表接下来有c组测试数据,每组占一行,其中: 字符1--26 分别代表 字符 'A'--'Z' ; 字符 ‘#’ 代表空格; 字符 ‘-’ 表示每个字母字符的间隔,不用管。 解题思路:先定义字符数组b[27]将26个字母装起来,b[0]设为0,方便一一对应,然后就直接判断,遇到 ‘#’ 直接输出空格字符 ‘ ’;遇到 ‘-’ 就继续;遇到字符数字就判断它接下来一位是否为字符数字,从而判断应该输出的对应字符。 再提一下:将字符数字转化成整型数值的方法是:字符数字-‘0’+0. 代码: #include <stdio.h> #include <stdlib.h> int main() { int c,i; char a[10005],b[27]= {'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; scanf("%d",&c); getchar(); //吃掉回车字符,避免将回车字符算进数组a中。 while(c--) { gets(a); for(i=0; a[i]!='\0'; i++) { if(a[i]=='#') printf(" "); else if(a[i]=='-') continue; else if(('0'<=a[i]&&a[i]<='9')&&('0'<=a[i+1]&&a[i+1]<='9')) { printf("%c",b[(10*(a[i]-'0'+0)+a[i+1]-'0'+0)]); i++; //记得再移动一位 } else printf("%c",b[a[i]-'0'+0]); } printf("\n"); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-52952.html

最新回复(0)