HDU 4287 Intelligent IME
Intelligent IME
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1348 Accepted Submission(s): 685
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
题意:根据题目中给的。小写字母都可以对应成一个数字。。先输入一个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的更多相关文章
- 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 hash
Intelligent IME Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- 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(string,map,stl,make_pair)
题目 转载来的,有些stl和string的函数蛮好的: //numx[i]=string(sx); //把char[]类型转换成string类型 // mat.insert(make_pair(num ...
- HDU 4287 Intelligent IME(字典树)
在我没用hash之前,一直TLE,字符串处理时间过长,用了hash之后一直CE,(请看下图)我自从经历我的字典树G++MLE,C++AC以后,一直天真的用C++,后来的CE就是因为这个,G++才支持这 ...
- 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 4287
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 #include<cstdio> #include<cstring> # ...
随机推荐
- 理解pkg-config工具
你在 Unix 或 Linux 下开发过软件吗?写完一个程序,编译运行完全正常,在你本机上工作得好好的,你放到源代码管理系统中.然后,告诉你的同事说,你可以取下来用了.这时,你长长的出了一口气,几天的 ...
- cos-26上传个人案例
package cn.gdpe.upload; import java.io.File;import java.io.IOException;import java.util.Enumeration; ...
- mysql锁死的现象判断
一般发生表锁死这种低级问题,就有两种情况:1.程序员水平太菜,2.程序逻辑错误. 一旦发生系统会出现超时,关键是有可能你看不到正在活动的php进程,而系统的慢查询日志也不会记录,只能通过show fu ...
- java高精度数组
POJ1205 递推公式为a[i] = 3*a[i-1] - a[i-2], a[1] = 1,a[2] = 3 , i 最高为100; 搞懂了使用BigInteger开数组. import java ...
- iOS · 安装RVM cocoaPods 及问题解决
一.安装RVM 1.RVM:ruby版本管理器,命令行工具 管理Ruby 开始安装吧~ 对!!就是这样换成taobao ⬇️ $ gem sources -l $ gem sources --remo ...
- SQL语句の集锦
6.删除数据后根据主键从备份表中恢复 insert sameTable_1 (name,dz) select name,dz from sameTable_1_bak where not exist ...
- [walkthrough] 在Asp.net MVC6 RC里使用NLog,并且把配置集成到config.json
说明一下:本文基于随visual studio 2015 RC公开的DNX1.0.0-beta4,git上最新的aspnet的开发版本已经发生了很大变化. 首先,理论部分看[汤姆大叔的博客] 解读AS ...
- IOS--UIImageView的使用方法
IOS--UIImageView的使用方法 //初始化 UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(10 ...
- 转:Gulp使用指南
原文来自于:http://www.techug.com/gulp Grunt靠边,全新的建构工具来了.Gulp的code-over-configuration不只让撰写任务(tasks)更加容易,也更 ...
- 1. android
http://blog.csdn.net/mirkerson/article/details/7238815