google在线测试练习题3
2014-10-12 11:23
267 查看
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
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
pause. For example,
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
Each message will consist of only lowercase characters
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.
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
Bfor 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 2indicates
AAwhereas
22indicates
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-zand 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.
#include<iostream> #include<fstream> using namespace std; int main() { int n_case; ifstream ifile("C-large-practice.in"); ofstream ofile("result_c2.txt"); ifile >> n_case; int reference[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; int replace[26] = {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}; for(int i = 0; i <= n_case; i++) { char line[1002]; ifile.getline(line, 1002); string words(line); if(i == 0) continue; ofile << "Case #" << i << ": "; for(int i = 0; i < words.length(); i++) { if(words[i] == ' ') { if(i - 1 >= 0 && words[i - 1] == ' ') ofile << ' ' << 0; else ofile << 0; } else { if(i - 1 >= 0 && reference[words[i] - 'a'] == reference[words[i - 1] - 'a']) ofile << ' ' << replace[words[i] - 'a']; else ofile << replace[words[i] - 'a']; } } ofile << endl; } return 0; }
相关文章推荐
- google在线测试练习题1
- google在线测试练习题2
- 三大翻译牛站,在线翻译测试,又是google的最好
- google校招在线测试题---2048
- hihocoder 在线测试 补提交卡 (Google)
- google在线测试练习2
- 2014 google (在线)测试笔试题解
- 2014校招 Google在线测试第二场题解 D
- 2014校招 Google在线测试第二场题解 E
- google在线測试练习题3
- google在线測试练习题1
- 2014校招 Google在线测试第二场题解 A
- 测试一下GOOGLE 的在线相册
- 2014校招 Google在线测试第二场题解 B
- 2014校招 Google在线测试第二场题解 C
- 2014校招 Google在线测试第二场题解 C
- 分享一个不错的正则表达式在线测试程序
- AQM在线竞技明星选拔赛 软件测试人的黄金机会
- 【软件测试】Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet
- Google推出在线日历