HDU 4287 Intelligent IME

http://acm.hdu.edu.cn/showproblem.php?pid=4287

MAP 无压力.

View Code
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <map>
 4 #include <string.h>
 5 using namespace std;
 6 int main()
 7 {
 8     int t,n,m,i,j,num;
 9     long ans[5005],sum,k;
10     char str[7];
11     int character[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};
12     scanf("%d",&t);
13     while(t--)
14     {
15         map<long,int> mark;
16         scanf("%d%d",&n,&m);
17         for(i=0;i<n;i++)
18         scanf("%ld",&ans[i]);
19         for(i=0;i<m;i++)
20         {
21             scanf("%s",str);
22             sum=0; k=1;
23             for(j=strlen(str)-1;j>=0;j--)
24             {
25                 sum+=character[str[j]-'a']*k;
26                 k*=10;
27             }
28             mark[sum]++;
29         }
30         for(i=0;i<n;i++)
31         {
32             printf("%d\n",mark[ans[i]]);
33         }
34     }
35     return 0;
36 }
原文地址:https://www.cnblogs.com/yoru/p/2679230.html