HDU 4287 Intelligent IME hash
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的更多相关文章
- HDU 4287 Intelligent IME(map运用)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 Intellig ...
- HDU 4287 Intelligent IME(字典树数组版)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4287 Intelligent IME
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)
Description We all use cell phone today. And we must be familiar with the intelligent English input ...
- HDU 4287 Intelligent IME(字典树)
在我没用hash之前,一直TLE,字符串处理时间过长,用了hash之后一直CE,(请看下图)我自从经历我的字典树G++MLE,C++AC以后,一直天真的用C++,后来的CE就是因为这个,G++才支持这 ...
- HDU 4287 Intelligent IME(string,map,stl,make_pair)
题目 转载来的,有些stl和string的函数蛮好的: //numx[i]=string(sx); //把char[]类型转换成string类型 // mat.insert(make_pair(num ...
- 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 ...
- hdu Intelligent IME
算法:字典树 题意:手机9键拼音:2:abc 3:def 4:ghi 5:jkl 6:mno 7:pqrs 8:tuv 9:wxyz: 第一行读入一个T,代表测试组数: 之后输入两个整数n和m, 有 ...
- hdu 4622 Reincarnation 字符串hash 模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有不超过1e5次的区间查询,输出每次查询区间中不同 ...
随机推荐
- java读取目录下所有csv文件数据,存入三维数组并返回
package dwzx.com.get; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; ...
- Appium过程中用到的adb点滴知识库
一.认识abd adb是什么? adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是d ...
- os和os.path模块
Os和os.path模块函数 1. Os模块 函数 描述 文件处理 Mkfifo()/mknod() 创建命名管道/创建文件系统节点 Remove()/unlink() 删除文件 Renam ...
- 用js完成blog项目
//前台调用 var $ = function (args) { return new Base(args); } //基础库 function Base(args) { //创建一个数组,来保存获取 ...
- .net/c#连接sqlserver
Webconfig代码 <configuration> <appSettings> <add key="myconnect" value=" ...
- filter在CSS中的效果
滤镜说明: Alpha:设置透明层次 blur:创建高速度移动效果,即模糊效果 Chroma:制作专用颜色透明 DropShadow:创建对象的固定影子 FlipH:创建水平镜像图片 FlipV:创建 ...
- kali 更新源
个人收集的kali 更新源: 修改更新源: vim /etc/apt/sources.list 更新源列表包: #apt-get update 更新系统软件: #apt-get upgrade #官方 ...
- javascript常用的小知识
1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu ...
- linux下find查找命令用法
Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时 ...
- CCF 201403-1 相反数 (水题)
问题描述 有 N 个非零且各不相同的整数.请你编一个程序求出它们中有多少对相反数(a 和 -a 为一对相反数). 输入格式 第一行包含一个正整数 N.(1 ≤ N ≤ 500). 第二行为 N 个用单 ...