Problem
The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. we wowould 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 characterBFor instance, the program wocould Press22. 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‘ ‘Shocould be printed to indicate a pause. For example,2 2IndicatesAAWhereas22IndicatesB.
Input
The first line of input gives the number of cases,N.NTest Cases Follow. Each case is a line of text formatted
desired_message
Each message will consist of only lowercase charactersA-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 online test exercise 3