传送门

问题描述:

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相关推荐

  1. HDU -4287 Intelligent IME 字典树数组模拟

    We all use cell phone today. And we must be familiar with the intelligent English input method on th ...

  2. HDU-4287 Intelligent IME

    题目:Intelligent IME Problem Description We all use cell phone today. And we must be familiar with the ...

  3. 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 ...

  4. HDU4287 Intelligent IME(Trie树,map)

    Problem Description We all use cell phone today. And we must be familiar with the intelligent Englis ...

  5. dd实现Linux转移,linux命令-dd {拷贝并替换}

    一 命令解释: dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 注意:指定数字的地方若以下列字符结尾,则乘以相应的数字:b=512:c=1:k=1024:w=2 参数注释: if=文 ...

  6. 字典树,01字典树,可持续化01字典树(总结+例题)

    目录 字典树 01字典树 字典树例题: power oj 2390: 查单词 HDU 1671 Phone List HDU 1004Let the Balloon Rise HDU 1075 Wha ...

  7. wince 6中硬键盘 输入法解决

    在一个项目中,我遇到了9宫格的键盘问题:wince下的keyboard的构架是native 方式,往 系统发送的是数字按键,要在wince上实现汉字或字母,就需要一个输入法来解析! 好在T9就是这样设 ...

  8. 输入法(IME)实现原理

    缘起 在windows下使用的sougou输入法,除了经常弹出广告,没有什么异常行为,Linux下的中文输入法似乎没那么强大好用了.起初用的是Ibus中的pinyin,后来因为机缘巧合装了yong输入 ...

  9. HDU 4775 Infinite Go 并查集

    题目链接:Infinite Go Infinite Go Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

最新文章

  1. request.getSession(false)到底返回什么
  2. Firefox Portable Developer 52.0.0.6176-6178
  3. 这家自动驾驶公司融资2.7亿美元,京东美团齐出手
  4. Linux系统时间和时序,什么是时序竞态 Linux系统时序竞态问题分析
  5. 在一个数组中找 差值最大的两个数 差值最小的两个数 推广到 点对
  6. 将Python字符串生成PDF
  7. linux中wps默认安装目录,centos6.5 安装wps linux
  8. 重磅发布|新一代云原生数据仓库AnalyticDB「SQL智能诊断」功能详解
  9. 牛赞:音视频前端跨平台技术应用
  10. 2011年三八妇女节搜索引擎LOGO设计欣赏
  11. Pandas知识点-逻辑运算
  12. 电脑桌面便签_电脑上哪些便签有提醒功能?求一款好用的电脑桌面提醒便签软件...
  13. ORACLE自增字段创建方法
  14. java项目中遇到的幂等性问题
  15. PHP开发环境搭建:PHP集成环境XAMPP 的安装与配置
  16. 对数换底公式及推导证明
  17. oracle11g64位怎么用sql,PLSQLDeveloper连接Oracle11g64位数据库配置详解(图文)
  18. Python 通过 Tushare Pro 获取财经数据接口
  19. 钟祥义工与残疾人互动频繁
  20. 去水印软件哪个好_去水印工具

热门文章

  1. php怎么替换斜杠,PHP 反斜杠如何替换掉?
  2. 自定义View实践:指南针的实现
  3. 【大牛感悟】淘宝陈吉平职业生涯--敬不甘平凡的自己
  4. Pandas读取excel数据——pearson相关性分析
  5. 敬伟PS教程:基础篇A
  6. 给电脑装一个双系统Linux,安装Linux让你的电脑变成双系统的七个理由
  7. selenium测试框架快速搭建(ui自动化测试)
  8. 使用LSTM神经网络+CTC loss识别freetype库生成的不定长验证码
  9. 1194:移动路线(简单题日常2)
  10. word文档打不开怎么办,word安全模式怎么解除,word打不开的解决办法