Intelligent IME

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1810    Accepted Submission(s): 897

Problem Description
We all use cell phone today. And we must be familiar with the intelligent English input method on the cell phone. To be specific, the number buttons may correspond to some English letters respectively, as shown below:

2 : a, b, c    3 : d, e, f    4 : g, h, i    5 : j, k, l    6 : m, n, o    

7 : p, q, r, s  8 : t, u, v    9 : w, x, y, z

When we want to input the word “wing”, we press the button 9, 4, 6, 4, then the input method will choose from an embedded dictionary, all words matching the input number sequence, such as “wing”, “whoi”, “zhog”. Here comes our question, given a dictionary, how many words in it match some input number sequences?

 
Input
First is an integer T, indicating the number of test cases. Then T block follows, each of which is formatted like this:

Two integer N (1 <= N <= 5000), M (1 <= M <= 5000), indicating the number of input number sequences and the number of words in the dictionary, respectively. Then comes N lines, each line contains a number sequence, consisting of no more than 6 digits. Then comes M lines, each line contains a letter string, consisting of no more than 6 lower letters. It is guaranteed that there are neither duplicated number sequences nor duplicated words.

 
Output
For each input block, output N integers, indicating how many words in the dictionary match the corresponding number sequence, each integer per line.

 
Sample Input
1
3 5
46
64448
74
go
in
night
might
gn
 
Sample Output
3
2
0
 
Source
 


 
题目意思就不多说了,将下面的字符串hash映射到上面的数字上即可。

AC代码:
#include<iostream>
#include<cstring>
using namespace std;
int hash1[1000005];
int a[5005];
char b[5005][8]; int cal(char *s)
{
int tmp=0;
int len=strlen(s),i;
for(i=0;i<len;i++)
{
if(s[i]>='a'&&s[i]<='c') tmp=tmp*10+2;
else if(s[i]>='d'&&s[i]<='f') tmp=tmp*10+3;
else if(s[i]>='g'&&s[i]<='i') tmp=tmp*10+4;
else if(s[i]>='j'&&s[i]<='l') tmp=tmp*10+5;
else if(s[i]>='m'&&s[i]<='o') tmp=tmp*10+6;
else if(s[i]>='p'&&s[i]<='s') tmp=tmp*10+7;
else if(s[i]>='t'&&s[i]<='v') tmp=tmp*10+8;
else if(s[i]>='w'&&s[i]<='z') tmp=tmp*10+9;
}
return tmp;
} int main()
{
int tes,i;
cin>>tes;
while(tes--)
{
int n,m;
cin>>n>>m;
for(i=0;i<n;i++)
cin>>a[i]; //存放数字
for(i=0;i<m;i++)
cin>>b[i];
memset(hash1,0,sizeof(hash1));
for(i=0;i<m;i++)
hash1[cal(b[i])]++;
for(i=0;i<n;i++)
cout<<hash1[a[i]]<<endl;
}
return 0;
} //406MS

hdu 4287Intelligent IME(简单hash)的更多相关文章

  1. HDU 4287-Intelligent IME(哈希)

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 2085 核反应堆 --- 简单递推

    HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...

  3. HDOJ-ACM1425 sort 简单hash应用

    其实快排也可以通过这个问题~不是考点 没想到考点是这个,简单hash应用,空间换时间 初始化一个长度为1000001的数组(由于数字的范围为[-500000,500000]) 如果存在这个数m,数组下 ...

  4. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

  5. 七夕节 (HDU - 1215) 【简单数论】【找因数】

    七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...

  6. HDU 1880 简单Hash

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=1880] 中文题面,题意很简单: 题解: 把每个 魔咒 和 对应的功能分别Hash,然后分别映射到ma ...

  7. HDU——2112HDU Today(SPFA+简单Hash或map+前向星)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. HDU 4821 String (HASH)

    题意:给你一串字符串s,再给你两个数字m l,问你s中可以分出多少个长度为m*l的子串,并且子串分成m个长度为l的串每个都不完全相同 首先使用BKDRHash方法把每个长度为l的子串预处理成一个数字, ...

  9. hdu 4622 Reincarnation 字符串hash 模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有不超过1e5次的区间查询,输出每次查询区间中不同 ...

随机推荐

  1. post登录趴一趴百度贴吧美女

    本次爬取的贴吧是百度的美女吧,给广大男同胞们一些激励 在爬取之前需要在浏览器先登录百度贴吧的帐号,各位也可以在代码中使用post提交或者加入cookie 爬行地址:http://tieba.baidu ...

  2. eclipse 的alt shift a,r 这个快捷键怎么操作 怎么按 eclipse 快捷键 逗号 什么意思

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha eclipse 的alt shift a,r 这个快捷键怎么操作 怎么按 eclipse ...

  3. noip2012疫情控制 题解

    题目大意 给出一棵n个节点的树,根是1,要在除根节点以外的点建立检查点,使得从每条根到叶子的路径上都至少存在一个检查点.检查点由军队来建立.初始军队的位置是给定的,移动军队走一条边需要花费这条边的权值 ...

  4. c++string函数详解

    string,一个极为好用了函数,学好了这些函数,在模拟以及字符串问题上,回节省很多很多的写代码时间,代码复杂度以及错误率,那么这一类函数都有那些功能呢?我们来逐一介绍(让你大吃一惊,还有这种操作?) ...

  5. 密码加密_md5

    md5加密 package com.fh.util; import java.security.MessageDigest; public class MD5 { public static Stri ...

  6. apache&mod_wsgi&django部署多个项目

    今天做好了第二个django项目,但在部署时出了一点小问题,在此记录一下. 1.mod_wsgi 3.4已经支持了部署多个项目,只需在httpd.conf中进行如下配置: WSGIScriptAlia ...

  7. BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 436  Solved: 187[Submit][S ...

  8. set bin 集合

    set: create table rr(zz char(4));create table test5 (rr set('美丽','态度好','温柔','善良'));insert into test5 ...

  9. 【java失业择业中】失业第四天:准备面试

    1.jQuery基础 学好jquery的一个基础条件是学好css层叠样式,因为很多时候这2个是一块配合使用的. 页面中很多需要jquery实现的效果只是通过jquery的选择器,选中要操作的元素,添加 ...

  10. 安装sql2012 正在启动操作系统功能"NetFx3"

    安装完windows8 后开始安装sql2012,安装过程中停在“正在启动操作系统功能"NetFx3"”不动了,很是着急,于是上网查了一下资料,原来NetFx3指的是Framewo ...