题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287

题意:用9宫格敲了N次,给m个字符串,问你每次敲击,能够敲出多少个单词

解法:Hash或者map模拟一下,水题

//HDU 4287

#include <bits/stdc++.h>
using namespace std;
map <int, int> mp1;
string s[5010];
map <string, int> mp2;
int ans[5010];

int main()
{
    int k = 2;
    for(int i = 0; i < 26; i++){
        if(i==3||i==6||i==9||i==12||i==15||i==19||i==22) k++;
        mp1[i]=k;
    }
    int t, n, m;
    scanf("%d", &t);
    while(t--){
        mp2.clear();
        memset(ans, 0, sizeof(ans));
        scanf("%d%d", &n, &m);
        for(int i = 0; i < n; i++) cin >> s[i];
        string s1;
        for(int i = 0; i < m; i++){
            cin >> s1;
            for(int j = 0; j < (int)s1.size(); j++){
                s1[j] = char(mp1[(s1[j]-'a')]+'0');
            }
            //cout << s1 << endl;
            mp2[s1]++;
        }
        for(int i = 0; i < n; i++) printf("%d\n", mp2[s[i]]);
    }
    return 0;
}