hdu: 4287
来源:互联网 发布:linux trap 编辑:程序博客网 时间:2024/06/10 03:18
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
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
#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<iostream>using namespace std;const int maxn=50009;char str[maxn][10],ste[10];map<string,int> mm;char ss[28]="22233344455566677778889999";struct trie{ int next[32]; int cnt; bool vis; void init() { vis=false; cnt=0; memset(next,0,sizeof(next)); }}tree[maxn];int index;void insert(char *s){ int len=strlen(s); int p=0; for(int i=0;i<len;i++) { int x=s[i]-'0'; if(tree[p].next[x]==0) { tree[index+1].init(); tree[p].next[x]=++index; } p=tree[p].next[x]; tree[p].cnt++; } tree[p].vis=true;}void find(char *s){ int len=strlen(s); int p=0; int flag=0; int x; for(int i=0;i<len;i++) { x=s[i]-'0'; if(tree[p].next[x]==0) { flag=1; printf("0\n"); return; } p=tree[p].next[x]; } if(tree[p].vis&&!flag) printf("%d\n",tree[p].cnt); else printf("0\n");}int main(){ int t,n,m; scanf("%d",&t); while(t--) { //mm.clear(); index=0; tree[0].init(); //char sss[maxn][12]; scanf("%d%d",&n,&m); for(int i=0; i<n; i++) scanf("%s",str[i]); for(int i=0; i<m; i++) { scanf("%s",ste); int len=strlen(ste); char sss[12]; for(int j=0; j<len; j++) { sss[j]=ss[ste[j]-'a']; } sss[len]='\0'; //mm[sss]++; //in++; //printf("%s\n",sss); insert(sss); }// for(int i=0; i<m; i++)// {// //string s=(string)(sss[i]);// mm[sss[i]]++;// //printf("%s\n",sss[i]);// //insert(sss[i]);// } for(int i=0; i<n; i++) { //printf("%d\n",mm[str[i]]); find(str[i]); } }}
0 0
- hdu 4287
- HDU 4287
- hdu: 4287
- hdu 4287 Intelligent IME
- HDU-4287-Intelligent IME
- HDU 4287 Intelligent IME
- hdu 4287 Intelligent IME
- Intelligent IME hdu 4287
- hdu 4287(水)
- HDU 4287 Intelligent IME
- hdu 4287 水题
- HDU 4287 Intelligent IME
- HDU 4287 (13.08.17)
- hdu 4287( PHONE LIST)
- HDU 4287 Intelligent IME
- hdu-4287 Intelligent IME
- hdu 4287 Intelligent IME
- HDU 4287 - Intelligent IME
- Bootstrap下载与安装(配图)
- 用pcl以某个视角显示rgbd
- SSH框架总结(框架分析+环境搭建+实例源码下载)
- html5的canvas的基础知识(ie9+)
- 安卓和h5交互
- hdu: 4287
- Nodejs学习路线图
- crontab文件编辑
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
- android之Activity的切换动画(进出动画)
- 欢迎使用CSDN-markdown编辑器
- ASP.NET 4.0的ClientIDMode属性
- Android AdapterViewFlipper控件的使用
- 客制化开机向导符合Google认证要求