/*
Time:2019.11.2
Author: Goven
type:字符串处理
err:
ref:
*/
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
map<char, string> morse, cnt;
map<string, char> opMorse;
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['?'] = "----";
int a[105];
for (map<char, string>::iterator it = morse.begin(); it != morse.end(); it++) {
opMorse[it -> second] = it -> first;
}
int n;
string s;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
string t = "";
int l = s.length();
for (int j = 0; j < l; j++) {
t += morse[s[j]];
a[j] = morse[s[j]].length();
}
string res = "";
int cnt = 0;
for (int j = l - 1; j >= 0; j--) {
res += opMorse[t.substr(cnt, a[j])];
cnt += a[j];
}
cout << i << ": " << res << endl;
}
return 0;
}
网友评论