hdu 4287Intelligent IME(简单hash)
Intelligent IME
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1810 Accepted Submission(s): 897
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?
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.
3 5
46
64448
74
go
in
night
might
gn
2
0
题目意思就不多说了,将下面的字符串hash映射到上面的数字上即可。
#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)的更多相关文章
- HDU 4287-Intelligent IME(哈希)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- HDOJ-ACM1425 sort 简单hash应用
其实快排也可以通过这个问题~不是考点 没想到考点是这个,简单hash应用,空间换时间 初始化一个长度为1000001的数组(由于数字的范围为[-500000,500000]) 如果存在这个数m,数组下 ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- 七夕节 (HDU - 1215) 【简单数论】【找因数】
七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...
- HDU 1880 简单Hash
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=1880] 中文题面,题意很简单: 题解: 把每个 魔咒 和 对应的功能分别Hash,然后分别映射到ma ...
- HDU——2112HDU Today(SPFA+简单Hash或map+前向星)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4821 String (HASH)
题意:给你一串字符串s,再给你两个数字m l,问你s中可以分出多少个长度为m*l的子串,并且子串分成m个长度为l的串每个都不完全相同 首先使用BKDRHash方法把每个长度为l的子串预处理成一个数字, ...
- hdu 4622 Reincarnation 字符串hash 模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有不超过1e5次的区间查询,输出每次查询区间中不同 ...
随机推荐
- 腾讯后台研发暑期实习offer经历
昨晚看到腾讯校招的微信状态,一颗心终于落下来了,终于可以去梦寐以求的鹅厂工作了.想想这一个多月以来,心情就像过山车一样,此起彼伏,一会充满希望,一会又跌入谷底. 三月份的时候,听说腾讯可以内推了,我内 ...
- java 继承 String类
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha String 类 是 final修饰 , 是不能 继承的.
- codevs 1226 倒水问题
1226 倒水问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 有两个无刻度标志的水壶,分别可装 x 升和 y 升 ( x, ...
- Virtual Judge SPOJ - LCS2 Longest Common Substring II
https://vjudge.net/problem/SPOJ-LCS2 SPOJ注册看不到验证码,气到暴毙,用vjudge写的. 注意!(对拍的时候发现)这份代码没有对只有一个字符串的情况进行处理! ...
- MySQL注射绕过技巧
本次对以前注入的一些总结. 总有在注入的时候发现有waf或者对参数过滤了 ~~ 做个文章记录下思路吧 ①.通过greatest函数绕过不能使用大小于符号的情况 我们在猜解单个字符时 通常会判断字符 ...
- [转]安卓虚拟机启动后报错: 类似 SDK Manager] Error: Error parsing .devices.xml 解决方案
昨天用android sdk manager 更新了android sdk, 我是在myeclipse上面安装adt来开发android的现在每次打开myeclipse都报错, 而且我每次打开虚拟机的 ...
- uva 6952 Cent Savings dp
Cent Savings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem/vie ...
- CodeM资格赛2
题目描述 组委会正在为美团点评CodeM大赛的决赛设计新赛制. 比赛有 n 个人参加(其中 n 为2的幂),每个参赛者根据资格赛和预赛.复赛的成绩,会有不同的积分.比赛采取锦标赛赛制,分轮次进行,设某 ...
- iis实现点击文件下载而不是打开文件
我们平时在搭建网站时,企业网站难免会做一些文档提供给用户下载,有时候我们会遇到提供EXE文件给客户下载时 客户打开文档链接时提示“无法找到该网页”也就是说我们的IIS环境不能下载EXE文件: IIS网 ...
- loading(正在加载特效)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...