G - Intelligent IME
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
HDU 4287
Description
We all use cell phone today. And we must be familiar with the intelligent English input method on the cell phone. To be specific, the number buttons may correspond to some English 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, then the input method will choose from an embedded dictionary, all words matching the input number sequence, such as “wing”, “whoi”, “zhog”. Here comes our question, given a dictionary, how many words in it match some input number sequences?
Output
For each input block, output N integers, indicating how many words in the dictionary match the corresponding number sequence, each integer per line.
分析:
这题用到map,最大的优点,他像字典一样是一一对应的关系,可以进行翻译转换
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<stdio.h>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
char v[5050]= {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 main()
{
int m,n,i,j,t,k,l;
map<int,int> p;
int a[5050];
scanf("%d",&t);
while(t--)
{
p.clear();
m=n=0;
scanf("%d %d",&n,&m);
for(i=0; i<n; i++)
cin>>a[i];
string te;
for(i=0; i<m; i++)
{
cin>>te;
l=te.length();
j=0;
for(k=0; k<l; k++)
j=j*10+v[te[k]-'a'];
p[j]++;
}
for(i=0; i<n; i++)
cout<<p[a[i]]<<endl;
}
return 0;
}