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. Inno Setup Winfrom 打包工具

    1.下载并安装Inno Setup 编译器 2.安装完成后打开Inno Setup 编译器: 3.选择[用「脚本向导」创建新的脚本文件(S)]: 4.点击[下一步]: 5.填写制作后程序的基本信息: ...

  2. hiho1291(逆序思维,并查集)

    题目链接:[https://hihocoder.com/problemset/problem/1291] 题意:在<我的世界>游戏中放置沙盒,沙盒为体积为1的正方体,按顺序给你一些坐标,然 ...

  3. jquery.rotate.js实现旋转动画

    1.页面引入jquery.rotate.js文件, 下载地址:https://files.cnblogs.com/files/zhoujl-5071/jquery.rotate.js(打开这个网址,c ...

  4. NOIP2017 D1T2时间复杂度

    这道题在考试时看到感觉与第一题放反了位置(因为我还没有看到第一题是结论题) 对于每个语句进行栈的模拟,而如果有语法错误就特判. 对于每一条for语句我们将其与栈顶元素连边,复杂度是1的我们不用考虑,如 ...

  5. Codeforces 408 E. Curious Array

    $ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...

  6. [BZOJ4555][TJOI2016&HEOI2016]求和(分治FFT)

    4555: [Tjoi2016&Heoi2016]求和 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 525  Solved: 418[Sub ...

  7. EMGU 2.9.X在VS2010下调试真正靠谱的配置

    emgu有多强大或者干什么的网上找资料吧.这里就说说我在2010下的配置的经历. 在网上找了很多资料,有细节到一步一步的,但我跟着弄还是没有成功.比如修改cpu,复制emgu的bin目录下某些所需文件 ...

  8. python爬虫我是斗图之王

    python爬虫我是斗图之王 本文会以斗图啦网站为例,爬取所有表情包. 阅读之前需要对线程池.连接池.正则表达式稍作了解. 分析网站 页面url分析 打开斗图啦网站,简单翻阅之后发现最新表情每页包含的 ...

  9. jquery datatables使用

    引入相应css 和js <link href="http://cdn.datatables.net/1.10.5/css/jquery.dataTables.css" rel ...

  10. POJ 1222 POJ 1830 POJ 1681 POJ 1753 POJ 3185 高斯消元求解一类开关问题

    http://poj.org/problem?id=1222 http://poj.org/problem?id=1830 http://poj.org/problem?id=1681 http:// ...