Intelligent IME

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4287

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

HINT

题意

用9宫格敲了N次,给m个字符串,问你每次敲击,能够敲出多少个单词

题解:

hash或者map搞一搞

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000009
#define eps 1e-7
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** //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
map<int,int> HH;
string s[];
map<string,int> H;
int ans[];
int main()
{
int k=;
for(int i=;i<=;i++)
{
if(i==||i==||i==||i==||i==||i==||i==)
k++;
HH[i]=k;
}
int t=read();
while(t--)
{
H.clear();
memset(ans,,sizeof(ans));
int n=read(),m=read();
for(int i=;i<n;i++)
cin>>s[i];
string s1;
for(int i=;i<m;i++)
{
cin>>s1;
for(int j=;j<s1.size();j++)
s1[j]=char(HH[(s1[j]-'a')]+'');
H[s1]++;
}
for(int i=;i<n;i++)
printf("%d\n",H[s[i]]);
}
}

HDU 4287 Intelligent IME hash的更多相关文章

  1. HDU 4287 Intelligent IME(map运用)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 Intellig ...

  2. HDU 4287 Intelligent IME(字典树数组版)

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

  3. HDU 4287 Intelligent IME

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

  4. ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)

    Description We all use cell phone today. And we must be familiar with the intelligent English input ...

  5. HDU 4287 Intelligent IME(字典树)

    在我没用hash之前,一直TLE,字符串处理时间过长,用了hash之后一直CE,(请看下图)我自从经历我的字典树G++MLE,C++AC以后,一直天真的用C++,后来的CE就是因为这个,G++才支持这 ...

  6. HDU 4287 Intelligent IME(string,map,stl,make_pair)

    题目 转载来的,有些stl和string的函数蛮好的: //numx[i]=string(sx); //把char[]类型转换成string类型 // mat.insert(make_pair(num ...

  7. Intelligent IME HDU - 4287 字典树

    题意: 给你m个字符串,每一个字符对应一个数字,如下: 2 : a, b, c    3 : d, e, f    4 : g, h, i    5 : j, k, l    6 : m, n, o ...

  8. hdu Intelligent IME

    算法:字典树 题意:手机9键拼音:2:abc  3:def 4:ghi 5:jkl 6:mno 7:pqrs 8:tuv 9:wxyz: 第一行读入一个T,代表测试组数: 之后输入两个整数n和m, 有 ...

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

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

随机推荐

  1. 一致性Hash算法在Memcached中的应用

    前言 大家应该都知道Memcached要想实现分布式只能在客户端来完成,目前比较流行的是通过一致性hash算法来实现.常规的方法是将server的hash值与server的总台数进行求余,即hash% ...

  2. 数组名的含义.xml

    pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...

  3. Cocos本地存储LocalStorage

    HTML5 LocalStorage 本地存储 //存档 var stopResumeMenu4 = cc.MenuItemFont.create("存档", this.onSav ...

  4. Jquery 等待ajax返回数据loading控件ShowLoading组件

    1.意义 开发项目中,前台的页面要发请求到服务器,服务器响应请求返回数据到前台,这段时间,有可能因为返回的数据量较大导致前台页面出现短暂性的等待,此时如果用户因不知情而乱点击有可能造成逻辑混乱,所以此 ...

  5. 服务框架Dubbo(转)

    add by zhj:该开源项目已经停止更新了,不过倒是可以学学该软件的架构设计 原文:http://www.oschina.net/p/dubbo Dubbo 是阿里巴巴公司开源的一个高性能优秀的服 ...

  6. nginx配置 首页不显示 index.html首页是显示域名

    原状况如下: 访问:www.test.com 敲回车后浏览器中自动跳转致: www.test.com/index.html 公司新需求如下: 访问:www.test.com 敲回车后浏览器中url不变 ...

  7. JPA多对多@manytomany注解配置实例

    维护端注解 @ManyToMany (cascade = CascadeType.REFRESH) @JoinTable (//关联表 name = "student_teacher&quo ...

  8. CCF 201312-5 I’m stuck! (暴力,BFS)

    问题描述 给定一个R行C列的地图,地图的每一个方格可能是'#', '+', '-', '|', '.', 'S', 'T'七个字符中的一个,分别表示如下意思: '#': 任何时候玩家都不能移动到此方格 ...

  9. Opencv2系列学习笔记10(提取连通区域轮廓)

    连通区域指的是二值图像中相连像素组成的形状.而内.外轮廓的概念及opencv1中如何提取二值图像的轮廓见我的这篇博客:http://blog.csdn.net/lu597203933/article/ ...

  10. android ViewConfiguration

    ViewConfiguration 1.有时候要获取一些android UI的中一些默认参数的来进行操作设置,就要用到ViewConfiguration 官方飞解释是:ViewConfiguratio ...