HDU 4287 Intelligent IME hash

题目链接: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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值