Intelligent IMETime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3487 Accepted Submission (s): 1659
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
Source2012 ACM/ICPC Asia Regional Tianjin Online
The main topic: Mobile phone keyboard with the number 2 corresponding to the letter has a,b,c;3 corresponding letter has d,e,f. Give some number strings such as 34, and some lowercase string. The number of occurrences of a numeric string corresponding to a lowercase letter. The string ABC corresponds to the number string is the 111,DH corresponding to the number string is 34. The lowercase string appears once in 111, and 34 appears once.
Puzzle: Because the string is the longest 6, so the direct translation of the given string, record translation is worth the number of queries can be.
#include <cstring> #include <algorithm> #include <iostream> #include <cstdio> #define N 5005using namespace Std;int n,m;int a[140];int b[n];void init () { int x=2; for (int i= ' a '; i<= ' o ', i+=3) {for (int j=i; j<i+3; j + +) a[j]=x; x + +; } a[' P ']=a[' Q ']=a[' R ']=a[' s ']=7; a[' t ']=a[' u ']=a[' V ']=8; a[' W ']=a[' x ']=a[' y ']=a[' z ']=9;} int Num[1000100];int Main () { //Freopen ("Test.in", "R", stdin); int t; Init (); cin>>t; while (t--) { scanf ("%d%d", &n,&m); for (int i=0; i<n; i++) scanf ("%d", &b[i]); memset (num,0,sizeof (num)); while (m--) { char s[20]; scanf ("%s", s); int sum=0; for (int i=0; s[i]; i++) sum=sum*10+a[s[i]; num[sum]++; } for (int i=0; i<n; i++) { printf ("%d\n", Num[b[i]]); } } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 4278 Intelligent IME