-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1051.cc
83 lines (75 loc) · 1.53 KB
/
1051.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Name: P,MTHBGWB
//Level: 1
//Category: シミュレーション,やるだけ
//Note:
/*
* やるだけ。
* モールス符号→文字と文字→モールス符号の変換テーブルを両方用意しておき、
* 問題文の通りに変換するだけ。
*/
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
string table[] = {
".-",
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
"-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--..",
};
int main() {
map<string, char> m;
map<char, string> rev;
for(int i = 0; i < 26; ++i) {
m[table[i]] = 'A'+i;
}
m["..--"] = '_';
m["---."] = '.';
m[".-.-"] = ',';
m["----"] = '?';
for(map<string, char>::iterator it = m.begin(); it != m.end(); ++it) rev[it->second] = it->first;
int N;
cin >> N;
for(int C = 1; C <= N; ++C) {
string str;
cin >> str;
vector<int> len;
string morse;
for(int i = 0; i < str.size(); ++i) {
const string &code = rev[str[i]];
morse += code;
len.push_back(code.size());
}
int pos = 0;
cout << C << ": ";
for(int i = 0; i < len.size(); ++i) {
cout << m[morse.substr(pos, len[len.size()-i-1])];
pos += len[len.size()-i-1];
}
cout << endl;
}
return 0;
}