Intelligent IMETime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3453 Accepted Submission (s): 1647
Problem Description We all use cell phone today. And we must is familiar with the intelligent 中文版 Input method on the cell phone. To is specific, the number buttons may correspond to some 中文版 letters respectively, as shown below:
2:a, B, C 3:d, E, F 4:g, H, I 5:j, K, L 6:M, N, O
7:p, Q, R, S 8:t, u, v 9:w, x, Y, Z
When we want to input the word "wing", we press the button 9, 4, 6, 4, and then the input method would choose from an embedded Dictionary, all words matching the input number sequence, such as "Wing", "Whoi", "Zhog". Here comes we question, given a dictionary, how many words in it match some input number sequences?
Input First is an integer T, indicating the number of test cases. Then T-Block follows, each of the which is formatted like this:
Both integer n (1 <= n <=), M (1 <= m <=), indicating the number of input number sequences and the Nu Mber of words in the dictionary, respectively. Then comes N lines, each line contains a number sequence, consisting of no more than 6 digits. Then comes M lines, each line contains a letter string, consisting of no more than 6 lower letters. It is guaranteed this there is neither duplicated number sequences nor duplicated words.
Output for each input block, output N integers, indicating how many words in the dictionary match the corresponding Numbe R sequence, each integer per line.
Sample Input
5466444874goinnightmightgn
Sample Output
320
with the map in STL class library, it is a water problem. The code is as follows:
#include <iostream> #include <string> #include <map> #include <cstring>using namespaceStd;Map<String ,int> M1; int Main (){String str;String num[ the]; int T,N,M,L;Cin>>T; while (T--) {Cin>>N>>M;L=N; for (int I=0;I<N;I++) {Cin>>Num[I]; } while ( M--) {Cin>>Str; for (int I=0;I<Str.Length();I + +) { if( Str[I]==' A '||Str[I]==' B '||Str[I]==' C ')Str[I]=' 2 '; else if (Str[I]==' d '||Str[I]==' E '||Str[I]==' F ')Str[I]=' 3 '; else if (Str[I]==' G '||Str[I]==' h '||Str[I]==' I ')Str[I]=' 4 '; else if (Str[I]==' J '||Str[I]==' K '||Str[I]==' l ')Str[I]=' 5 '; else if (Str[I]==' m '||Str[I]==' n '||Str[I]==' O ')Str[I]=' 6 '; else if (Str[I]==' P '||Str[I]==' Q '||Str[I]==' R '||Str[I]==' s ')Str[I]=' 7 '; else if (Str[I]==' t '||Str[I]==' u '||Str[I]==' V ')Str[I]=' 8 '; else if (Str[I]==' W '||Str[I]==' x '||Str[I]==' y '||Str[I]==' Z ')Str[I]=' 9 ';M1[Str]++; }} for (int I=0;I<N;I++) {cout<<M1[Num[I]]<<Endl; }M1.Clear(); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Readers are welcome to comment and correct
Hangzhou Electric (HDU) ACM 4287 Intelligent IME