杭电ACM 1982 运用映射来做
来源:互联网 发布:建筑工程资料员软件 编辑:程序博客网 时间:2024/05/22 12:26
Kaitou Kid - The Phantom Thief (1)
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2931 Accepted Submission(s): 1280
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
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
49#23-9-12-12#19-20-5-1-12#1-20#12-5-1-19-20#15-14-5#10-5-23-5-121-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-191-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-147-15-15-4#12-21-3-11
Sample Output
I WILL STEAL AT LEAST ONE JEWELAND LEAVE THE MUSEUM IN T MINUTESAFTER THE OPENING OF THE EXHIBITIONGOOD LUCK
解题思路:有题意可知9--英文字母第九个“I”,23--对应“W”,,,可以想到用映射来解决这个问题。但是这里需要注意的是像23它并不是一个字符而是占了两个字符,对此我给出的方案是下面代码的红色代码。
此外要特别注意下面的紫色代码,不能缺少i++,如果少了i++,像23中的3就会多读一次。
#include<iostream>#include<string>using namespace std;char s[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'};int main(){ int n,sum; string str; while(cin>>n) { while(n--) { cin>>str; for (int i = 0; i < str.length(); i++) { if(str[i] == '#') cout<<" "; else if(str[i] == '-') continue; else { if(str[i + 1] >= '0' && str[i + 1] <= '9') { <span style="color:#cc0000;">sum = 10 * (str[i] - '0') + str[i + 1] - '0';</span> cout<<s[sum]; <span style="color:#993399;">i++;</span> } else cout<<s[str[i] - '0']; } } cout<<endl; } } return 0;}
0 0
- 杭电ACM 1982 运用映射来做
- 杭电 ACM 1106 排序 可以用strtok 来做
- 杭电ACM 1425 hash函数运用
- 做了几天杭电ACM感想
- 杭电acm 4268 Alice and Bob set的运用
- 杭电acm 4414 Finding Crosses dfs的运用
- 杭电ACM-HDU 1982
- 杭电ACM 2503 a/b + c/d&&&&杭电ACM 2504又见GCD--(递归运用)----20140725
- 杭电ACM 2500 做一个正气的杭电人
- 西电ACM 1003 亮亮做加法
- 杭电ACM 1003
- 杭电 ACM 2016
- 杭电acm 1010
- 杭电 acm 1045
- 杭电ACM-1010
- 杭电ACM 1172
- 杭电ACM 1174
- 杭电ACM 1175
- HDU 5738 Eureka
- Android 移动开发--遇到问题及解决(一)
- mfc应用程序通过设置选项来出现console控制台输出窗口
- CodeForces 489B BerSU Ball
- 《30天自制操作系统》 day3 小结
- 杭电ACM 1982 运用映射来做
- php中带关键字搜索功能的分页函数的设计及实例
- 机房合作--大战类图
- HDOJ 2289 Cup
- poj 1182 推理 || 简单方法
- HDU—1009—FatMouse' Trade
- 威威猫系列故事——打地鼠
- hashmap的底层实现
- ThinkPHP的四种路由形式