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;
}