forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht9spelling.cpp
42 lines (40 loc) · 980 Bytes
/
t9spelling.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main() {
int times;
cin >> times;
vector<string> chars =
{"2","22","222",
"3","33","333",
"4","44","444",
"5","55","555",
"6","66","666",
"7","77","777","7777",
"8","88","888",
"9","99","999","9999",
"0"};
cin.ignore();
for(int i = 0; i < times; i++) {
string line;
getline(cin,line);
cout << "Case #" << i+1 << ": ";
int prev = 0;
for(auto c : line) {
if(c != ' ') {
if(chars[prev][0] == chars[c-'a'][0]) {
cout << " ";
}
cout << chars[c-'a'];
prev = c-'a';
}
else if(c == ' ' && prev == 26) {
cout << " 0";
}
else {
cout << "0";
prev = 26;
}
}
cout << endl;
}
}