HDU4287:Intelligent IME
来源:互联网 发布:java c s 开发框架 编辑:程序博客网 时间:2024/06/09 14:28
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?
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.
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
13 5466444874goinnightmightgn
Sample Output
320
用哈希进行保存即可
#include <stdio.h>#include <string.h>int num[5005];char word[5005][10];int hash[1000010];char kind[30] = "22233344455566677778889999";//打表int main(){ int t; scanf("%d",&t); while(t--) { int n,m; memset(hash,0,sizeof(hash)); scanf("%d%d",&n,&m); int i,j; for(i = 0;i<n;i++) scanf("%d",&num[i]); for(i = 0;i<m;i++) scanf("%s",word[i]); int tem; for(i = 0;i<m;i++) { int len = strlen(word[i]); tem = 0; for(j = 0;j<len;j++) { tem = tem*10+(kind[word[i][j]-'a']-'0');//吧单词转换为数字 } for(j = 0;j<n;j++) { if(tem == num[j]) { hash[tem]++; break; } } } for(i = 0;i<n;i++) { printf("%d\n",hash[num[i]]); } } return 0;}
- 【STL】 hdu4287 Intelligent IME
- HDU4287:Intelligent IME
- HDU4287- Intelligent IME
- hdu4287 Intelligent IME
- hdu4287 Intelligent IME--哈希表
- Trie树 hdu4287 Intelligent IME
- hdu4287 Intelligent IME-字典树
- hdu4287 Intelligent IME (字典树)
- hdu4287 Intelligent IME(字典树)
- hdu4287 Intelligent IME-----天津网络赛
- hdu4287 Intelligent IME STLmap散列查找
- HDU4287 Intelligent IME(Trie树,map)
- Intelligent IME
- Intelligent IME
- Intelligent IME
- hdu 4287 Intelligent IME
- HDU-4287-Intelligent IME
- HDU 4287 Intelligent IME
- s3c2440数据手册的bug
- 如何建立软件开发项目里程碑
- 在Unity中不显示挂载的NTFS磁盘
- IBM实习生笔试题目(1)
- CGI编程学习
- HDU4287:Intelligent IME
- 字符串四则运算表达式的计算(华为机试)
- 关于英语学习工具
- iOS 开源网站
- python的os.path.join
- SQL中char、varchar、nvarchar的区别
- C#利用word2007插件实现word转pdf
- 操作系统内存管理与简单分配器实现
- WPS for Linux beta1 正式发布公测