T9 Spelling-GOOGLE CODE JAM AFICA 2010 Qualification Round

题目来源:http://code.google.com/codejam/contest/dashboard?c=351101#s=p2

 

关键就是计算字母对应的数字吧,比较关键的是7和9这两个数,他们对应了4个字母,我觉得我处理的方法有些赖皮了,不知道高手们有什么其他方法吗?

 

#include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; int main() { int cnt,i,j; ifstream fcin("C-large-practice.in"); ofstream fcout("C-large-practice.out"); fcin >> cnt; fcin.get(); //回车 vector<string> line; string in; char temp; int cur_num,last_num=-1,k; while(cnt>0) { getline(fcin,in); line.push_back(in); cnt--; } i=0; for(vector<string>::iterator it=line.begin();it!=line.end();it++) //对line[i]做处理 { fcout << "Case #" << ++i << ": "; for(j=0;j<(*it).length();j++) { temp=(*it)[j]; if(temp==' ') { cur_num=0; if(cur_num==last_num) fcout << ' '; fcout << cur_num; last_num=0; } else { cur_num=temp-'a'; if(cur_num>17) cur_num--; if(cur_num==24) cur_num--; if((cur_num/3+2)==last_num) fcout << ' '; last_num=cur_num/3+2; for(k=0;k<=cur_num%3;k++) fcout << last_num; if(temp=='s'||temp=='z') fcout << last_num; } } fcout << endl; } return 0; }

 

附录:

Problem

The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as shown below. To insert the character B for instance, the program would press 22. In order to insert two characters in sequence from the same key, the user must pause before pressing the key a second time. The space character ' ' should be printed to indicate a pause. For example, 2 2 indicates AA whereas 22 indicates B.

Input

The first line of input gives the number of cases, N. N test cases follow. Each case is a line of text formatted as

desired_message

Each message will consist of only lowercase characters a-z and space characters ' '. Pressing zero emits a space.

Output

For each test case, output one line containing "Case #x: " followed by the message translated into the sequence of keypresses.

Limits

1 ≤ N ≤ 100.

Small dataset

1 ≤ length of message in characters ≤ 15.

Large dataset

1 ≤ length of message in characters ≤ 1000.

Sample


Input

Output
4
hi
yes
foo  bar
hello world

Case #1: 44 444
Case #2: 999337777
Case #3: 333666 6660 022 2777
Case #4: 4433555 555666096667775553

你可能感兴趣的:(iterator,insert,character,dataset,output,2010)