HDU - 4287 Intelligent IME
传送门
问题描述:
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?
输入说明:
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.
输出说明:
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
SAMPLEOUTPUT:
3
2
0
思路:
题目的意思就是九个数字分别代表不同的字母(对应关系在题目中有所说明,其实就是一个九键键盘)然后给我们一串数字,问我们这些数组能对应哪些字母的组合。做法是去建立一个字典树,令a~z对应的数字都表现出来,先输入数字组合,再输入字符数组(代表了单词,用tree函数处理,得到对应的数字,对应数字的value++)最后输出各项的value即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
string num[30030];
int n,m;
map<string,int>a;
char dictionary(char ch)
{if(ch=='a'||ch=='b'||ch=='c'){return '2';}else if(ch=='d'||ch=='e'||ch=='f'){return '3';}else if(ch=='g'||ch=='h'||ch=='i'){return '4';}else if(ch=='j'||ch=='k'||ch=='l'){return '5';}else if(ch=='m'||ch=='n'||ch=='o'){return '6';}else if(ch=='p'||ch=='q'||ch=='r'||ch=='s'){return '7';}else if(ch=='t'||ch=='u'||ch=='v'){return '8';}else{return '9';}
}
string tree(string s )
{string tem="";int len=s.length();for( int i=0;i<len;i++){tem+=dictionary(s[i]);}return tem;
}
int main()
{int t,i,len;string s;cin>>t;while(t--){a.clear();cin>>n>>m;for(i=1;i<=n;i++){cin>>num[i];}for(i=1;i<=m;i++){cin>>s;a[tree(s)]++;}for(int i=1;i<=n;i++){cout<<a[num[i]]<<endl;}}return 0;
}
HDU - 4287 Intelligent IME相关推荐
- HDU -4287 Intelligent IME 字典树数组模拟
We all use cell phone today. And we must be familiar with the intelligent English input method on th ...
- HDU-4287 Intelligent IME
题目:Intelligent IME Problem Description We all use cell phone today. And we must be familiar with the ...
- hdu 4287 sdnu 1119 Intelligent IME
原题链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=4287 sdnu: http://210.44.14.31/problem/show/111 ...
- HDU4287 Intelligent IME(Trie树,map)
Problem Description We all use cell phone today. And we must be familiar with the intelligent Englis ...
- dd实现Linux转移,linux命令-dd {拷贝并替换}
一 命令解释: dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 注意:指定数字的地方若以下列字符结尾,则乘以相应的数字:b=512:c=1:k=1024:w=2 参数注释: if=文 ...
- 字典树,01字典树,可持续化01字典树(总结+例题)
目录 字典树 01字典树 字典树例题: power oj 2390: 查单词 HDU 1671 Phone List HDU 1004Let the Balloon Rise HDU 1075 Wha ...
- wince 6中硬键盘 输入法解决
在一个项目中,我遇到了9宫格的键盘问题:wince下的keyboard的构架是native 方式,往 系统发送的是数字按键,要在wince上实现汉字或字母,就需要一个输入法来解析! 好在T9就是这样设 ...
- 输入法(IME)实现原理
缘起 在windows下使用的sougou输入法,除了经常弹出广告,没有什么异常行为,Linux下的中文输入法似乎没那么强大好用了.起初用的是Ibus中的pinyin,后来因为机缘巧合装了yong输入 ...
- HDU 4775 Infinite Go 并查集
题目链接:Infinite Go Infinite Go Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU——1106排序(istringstream的使用、STLvector练习)
排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
最新文章
- request.getSession(false)到底返回什么
- Firefox Portable Developer 52.0.0.6176-6178
- 这家自动驾驶公司融资2.7亿美元,京东美团齐出手
- Linux系统时间和时序,什么是时序竞态 Linux系统时序竞态问题分析
- 在一个数组中找 差值最大的两个数 差值最小的两个数 推广到 点对
- 将Python字符串生成PDF
- linux中wps默认安装目录,centos6.5 安装wps linux
- 重磅发布|新一代云原生数据仓库AnalyticDB「SQL智能诊断」功能详解
- 牛赞:音视频前端跨平台技术应用
- 2011年三八妇女节搜索引擎LOGO设计欣赏
- Pandas知识点-逻辑运算
- 电脑桌面便签_电脑上哪些便签有提醒功能?求一款好用的电脑桌面提醒便签软件...
- ORACLE自增字段创建方法
- java项目中遇到的幂等性问题
- PHP开发环境搭建:PHP集成环境XAMPP 的安装与配置
- 对数换底公式及推导证明
- oracle11g64位怎么用sql,PLSQLDeveloper连接Oracle11g64位数据库配置详解(图文)
- Python 通过 Tushare Pro 获取财经数据接口
- 钟祥义工与残疾人互动频繁
- 去水印软件哪个好_去水印工具