poj1051 模拟
来源:互联网 发布:iphone抢购软件 编辑:程序博客网 时间:2024/04/30 11:09
题意:输入字符串,转换为morse码,求将该morse码对应的数字串反转后所对应的morse码。
例如:AKADTOF_IBOETATUK_IJN先转为morse码
.--.-.--..----..-...--..-...---.-.--..--.-..--...----.232313442431121334242
将数字翻转为242433121136266313232,此时morse码为:
.--.-.--..----..-...--..-...---.-.--..--.-..--...----.242433121136266313232
最后再转为文本ACM_GREATER_NY_REGION
算法:模拟,水题。
#include <iostream>#include <map>#include <string>using namespace std;map <char, string> morse;map <string, char> remorse;void init(){ morse['A'] = ".-"; morse['B'] = "-..."; morse['C'] = "-.-."; morse['D'] = "-.."; morse['E'] = "."; morse['F'] = "..-."; morse['G'] = "--."; morse['H'] = "...."; morse['I'] = ".."; morse['J'] = ".---"; morse['K'] = "-.-"; morse['L'] = ".-.."; morse['M'] = "--"; morse['N'] = "-."; morse['O'] = "---"; morse['P'] = ".--."; morse['Q'] = "--.-"; morse['R'] = ".-."; morse['S'] = "..."; morse['T'] = "-"; morse['U'] = "..-"; morse['V'] = "...-"; morse['W'] = ".--"; morse['X'] = "-..-"; morse['Y'] = "-.--"; morse['Z'] = "--.."; morse['_'] = "..--"; morse['.'] = "---."; morse[','] = ".-.-"; morse['?'] = "----"; remorse[".-"] = 'A'; remorse["-..."] = 'B'; remorse["-.-."] = 'C'; remorse["-.."] = 'D'; remorse["."] = 'E'; remorse["..-."] = 'F'; remorse["--."] = 'G'; remorse["...."] = 'H'; remorse[".."] = 'I'; remorse[".---"] = 'J'; remorse["-.-"] = 'K'; remorse[".-.."] = 'L'; remorse["--"] = 'M'; remorse["-."] = 'N'; remorse["---"] = 'O'; remorse[".--."] = 'P'; remorse["--.-"] = 'Q'; remorse[".-."] = 'R'; remorse["..."] = 'S'; remorse["-"] = 'T'; remorse["..-"] = 'U'; remorse["...-"] = 'V'; remorse[".--"] = 'W'; remorse["-..-"] = 'X'; remorse["-.--"] = 'Y'; remorse["--.."] = 'Z'; remorse["..--"] = '_'; remorse["---."] = '.'; remorse[".-.-"] = ','; remorse["----"] = '?';}int main(){int cases;string str, ans,morse_str;int p[110];init();cin >> cases;for (int i=1; i<=cases; i++){cin >> str;morse_str = "";int len = str.length();cout << i << ": ";// 将输入的字符串转换为morse码 for (int j=0; j<len; j++){morse_str += morse[str[j]];p[j] = morse[str[j]].length();}// 按数字逆序输出morse码对应的文本 int start=0;for (int j=len-1; j>=0; j--){cout << remorse[morse_str.substr(start,p[j])] ;start += p[j];}cout << endl;}}
0 0
- poj1051 模拟
- poj1051 细心模拟
- POJ1051
- poj1051解题报告
- hdu1065&&poj1051 Wooden Sticks
- POJ1051 木棍叠加
- acm-poj1051解题报告
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟:
- 模拟
- hdu1163Eddy's digital Roots
- Android自定义View实战-100行带你写出SwitchButton
- 窗位和窗宽
- 2016年4月21日百度笔试题--SubBinaryTree
- 344. Reverse String [E]
- poj1051 模拟
- SC OpenService 失败5:拒绝访问
- 【APM】第一个应用程序
- 深入浅出java虚拟机系列:(三)jvm常用垃圾收集器
- ps学习记录
- 奇特的可变参数列表实现print函数
- 如何记录MySQL执行过的SQL语句?
- Mac下使用命令行和clover制作原版10.11.4启动U盘
- PHP的相关知识点