您的位置:首页 > 其它

hdu 4287 Intelligent IME map的应用

2012-09-11 23:47 106 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4287

题意:

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

思路:

才开始想复杂了,其实只要用一个map即可。

View Code

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>

#define CL(a,num) memset((a),(num),sizeof(a))
#define iabs(x)  ((x) > 0 ? (x) : -(x))
#define Min(a,b) (a) > (b)? (b):(a)
#define Max(a,b) (a) > (b)? (a):(b)

#define ll long long
#define inf 0x7f7f7f7f
#define MOD 100000007
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define test puts("<------------------->")
#define maxn 100007
#define M 100007
#define N 50007
using namespace std;
//freopen("din.txt","r",stdin);

int a
;
map<int,int>mp;
int n,m;

int find(char *s){
int i;
int len = strlen(s);
int num = 0;
for (i = 0; i < len; ++i){
if (s[i] == 'a' || s[i] == 'b' || s[i] == 'c') num = num*10 + 2;
if (s[i] == 'd' || s[i] == 'e' || s[i] == 'f') num = num*10 + 3;
if (s[i] == 'g' || s[i] == 'h' || s[i] == 'i') num = num*10 + 4;
if (s[i] == 'j' || s[i] == 'k' || s[i] == 'l') num = num*10 + 5;
if (s[i] == 'm' || s[i] == 'n' || s[i] == 'o') num = num*10 + 6;
if (s[i] == 'p' || s[i] == 'q' || s[i] == 'r' || s[i] == 's') num = num*10 + 7;
if (s[i] == 't' || s[i] == 'u' || s[i] == 'v') num = num*10 + 8;
if (s[i] == 'w' || s[i] == 'x' || s[i] == 'y' || s[i] == 'z') num = num*10 + 9;
}
return num;
}
int main(){

//freopen("din.txt","r",stdin);
int i,t;
char str[10];
scanf("%d",&t);
while (t--){
scanf("%d%d",&n,&m);
for (i = 0; i < n; ++i) scanf("%d",&a[i]);
mp.clear();
for (i = 0; i < m; ++i){
scanf("%s",str);
int x = find(str);
mp[x]++;
}
for (i = 0; i < n; ++i){
printf("%d\n",mp[a[i]]);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: