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. javascript-处理XML

    /** * Created by Administrator on 2015/4/4. */ var XmlUtil=(function () { var createDocument= functi ...

  2. xubuntu14.04截图,彻底到Linux一个半月后记

        前言 自学计算机技术,越到后面,越依赖ubuntu,以致于很多时候都是一开机就打开虚拟机上的ubuntu10.04,Linux已经变得越来越重要了. 2014-04-17,ubuntu14.0 ...

  3. 关于this

    一:全局环境中的this指的是window对象 二:作为对象的方法调用 当函数作为对象的方法被调用时,this指向该对象 例子: 三:作为普通方法调用 当函数不作为对象的属性被调用,而是作为普通函数函 ...

  4. iOS适配:Masonry介绍与使用实践:快速上手Autolayout

    随着iPhone的手机版本越来越多, 那么对于我们广大的开发者来说就是很悲催,之前一直使用代码里面layout的约束来适配, 现在推荐一个第三方Masonry,上手块,操作简单,只能一个字形容他 “爽 ...

  5. ASP.NET Web API下Controller激活

    一.HttpController激活流程 对于组成ASP.NET Web API核心框架的消息处理管道来说,处于末端的HttpMessageHandler是一个HttpRoutingDispatche ...

  6. Laravel框架——自己写的类找不到

    composer.json my model files are stored in directory of app\models, therefor "autoload": { ...

  7. WPF学习笔记-TextBox光标位置如何放到最后?

    TextBox光标位置如何放到最后? 使用SelectionStart : TextBox.SelectionStart = TextBox.Text.Length;

  8. nginx+uwsgi+django

    上一涨讲解了如何使用nginx+uwsgi部署wsgi application 其实django配置方式和 application都一样,因为如果我们对application进行扩展就是一个WSGI ...

  9. 深入浅出C语言中的堆和栈

    在谈堆栈的时候,我在这有必要把计算机的内存结构给大家简单的介绍下(高手们可以直接飘过) 一. 内存结构   每个程序一启动都有一个大小为4GB的内存,这个内存叫虚拟内存,是概念上的,真正能用到的,只是 ...

  10. JSP - request - 1

    <%@ page language="java" contentType="text/html;charset=utf8" %> <%@ pa ...