HDU4287Intelligent IME

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


2012天津online


题意:

给出n个手机数字序列,m个英文组合,求每个数字序列对应的可能的英文组合在下边的出现了多少个。


英文组合不超过6个字母,故可以将英文组合直接化成数字后处理。


#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include<cstdlib>
#include <algorithm>
#include<string>
#include <time.h>
using namespace std;
const double eps=1e-7;
const int INF=(1<<30)-1;
//const double INF=1e50;
//const double pi=acos(-1);

#define N 5005
#define M 100005

int a[N];
char st[N];
multiset<int> b;

int main()
{
    //freopen("a","r",stdin);

    int T,i,j,kk,l,w,s,h,n,m;

    scanf("%d",&T);
    for (kk=1;kk<=T;kk++)
    {
        scanf("%d%d",&n,&m);

        for (i=1;i<=n;i++) scanf("%d\n",&a[i]);

        b.clear();
        for (i=1;i<=m;i++)
        {
            gets(st);
            l=strlen(st)-1;
            w=1;
            s=0;

            for (j=l;j>=0;j--)
            {
                if (st[j]>='a' && st[j]<='c') h=2;
                else if (st[j]>='d' && st[j]<='f') h=3;
                else if (st[j]>='g' && st[j]<='i') h=4;
                else if (st[j]>='j' && st[j]<='l') h=5;
                else if (st[j]>='m' && st[j]<='o') h=6;
                else if (st[j]>='p' && st[j]<='s') h=7;
                else if (st[j]>='t' && st[j]<='v') h=8;
                else if (st[j]>='w' && st[j]<='z') h=9;

                s+=h*w;
                w*=10;
            }

            b.insert(s);
        }

        for (i=1;i<=n;i++)
        printf("%d\n",b.count(a[i]));
    }

    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值