Skip to content

Instantly share code, notes, and snippets.

@elgeish
Created March 21, 2014 05:50
Show Gist options
  • Save elgeish/9680291 to your computer and use it in GitHub Desktop.
Save elgeish/9680291 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<map>
using namespace std;
map<char, int> t9;
void solve() {
char prev = -1, cur;
while((cur = cin.get()) != '\n') {
if (prev != -1 && t9[cur] % 10 == t9[prev] % 10)
cout << ' ';
cout << t9[cur];
prev = cur;
}
}
int main() {
int freq[] = { 3, 3, 3, 3, 3, 4, 3, 4 };
int key = 2, t = 1, N;
char c = 'a';
for (int i = 0; i < 8; ++i, ++key)
for (int j = 1, code = key; j <= freq[i]; ++j, ++c, code = code * 10 + key)
t9[c] = code;
t9[' '] = 0;
cin >> N; cin.get();
while (t <= N)
cout << "Case #" << t++ << ": ", solve(), cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment