Intelligent IME

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

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

题意:根据题目中给的。小写字母都可以对应成一个数字。。先输入一个n,一个m,接下去输入n个号码,m个小写字母组成的号码。要求出n个号码中每个在m个小写字母中出现的次数。。

思路:。由于只有6位数。直接开个100W的数组标记每个号码就可以了。。 每次小写字母转换成的号码就在该号码加一。最后输出就可以了。。

代码:

#include <stdio.h>
#include <string.h>
#include <map>
#include <string>
using namespace std; int t;
int n, m;
int vis[1000];
int sb[5005];
int hash[1000005];
int main() {
vis['a'] = vis['b'] = vis['c'] = 2;
vis['d'] = vis['e'] = vis['f'] = 3;
vis['g'] = vis['h'] = vis['i'] = 4;
vis['j'] = vis['k'] = vis['l'] = 5;
vis['m'] = vis['n'] = vis['o'] = 6;
vis['p'] = vis['q'] = vis['r'] = vis['s'] = 7;
vis['t'] = vis['u'] = vis['v'] = 8;
vis['w'] = vis['x'] = vis['y'] = vis['z'] = 9;
scanf("%d", &t);
while (t --) {
memset(hash, 0, sizeof(hash));
memset(sb, 0, sizeof(sb));
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i ++)
scanf("%d", &sb[i]);
getchar();
for (int i = 0; i < m; i ++) {
char sbbb[10];
int num = 0;
gets(sbbb);
for (int j = 0; j < strlen(sbbb); j ++)
num = num * 10 + vis[sbbb[j]];
hash[num] ++;
}
for (int i = 0; i < n; i ++)
printf("%d\n", hash[sb[i]]);
}
return 0;
}

HDU 4287 Intelligent IME的更多相关文章

  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 hash

    Intelligent IME Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  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(string,map,stl,make_pair)

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

  6. HDU 4287 Intelligent IME(字典树)

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

  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 4287

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 #include<cstdio> #include<cstring> # ...

随机推荐

  1. Fedora 21 安装Infinality

    原文地址: Fedora 21 用infinality美化你的字体 http://blog.csdn.net/element207/article/details/41746683 安装infinal ...

  2. 移动Web开发,4行代码检测浏览器是否支持position:fixed

    不废话,直接上代码 var div = document.createElement('div'); div.style.cssText = 'display:none;position:fixed; ...

  3. php 上传视频的代码

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  4. OpenGrok的安装

    http://opengrok.github.io/OpenGrok/ Ubuntu环境下OpenGrok的安装及使用 http://www.linuxidc.com/Linux/2013-05/84 ...

  5. 关于android:configChanges的属性

    一般在AndroidManifest.xml文件中都没有使用到android:configChanges="keyboardHidden|orientation"配置,当然还是很有 ...

  6. 关于DEDECMS目录移动方法

    最近在做一个美容医院的站,由于我的本地的PHP服务器上有几个站,又不能放在根目录下,只能在根目录下新建一个目录来存放这个站,于是就有了这篇文章. 如果我们直接将根目录下的A文件夹下的DEDECMS文件 ...

  7. mysql的SQL_CALC_FOUND_ROWS 使用

    mysql的SQL_CALC_FOUND_ROWS 使用 标签: sqlmysqltable 2007-02-27 11:40 5073人阅读 评论(0) 收藏 举报  分类: Mysql数据库技术( ...

  8. Replicate String in C#

    My original posting on string repetition caused a couple responses, and is currently among the Top P ...

  9. width:auto; 和 width:100%;的不同

    width:auto:会将元素撑开至整个父元素width,但是会减去子节点自己的margin,padding或者border的大小.width:100%:会强制将元素变成和父元素一样的宽,并且添加额外 ...

  10. 【HDOJ】2333 Assemble

    二分+贪心策略.其中注释处很重要. #include <iostream> #include <cstdio> #include <cstring> #includ ...