hdu4287 Intelligent IME--哈希表
来源:互联网 发布:java socket 心跳实例 编辑:程序博客网 时间:2024/05/14 20:00
原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=4287
一:原题内容
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
二:分析理解
这题不难,直接看代码吧。
三:AC代码
#include<iostream> #include<string.h> #include<algorithm> using namespace std;int num[5005];char word[5005][8];int hash1[1000010];char kind[] = "22233344455566677778889999";int T;int n, m;int main(){scanf("%d", &T);while (T--){scanf("%d%d", &n, &m);memset(hash1, 0, sizeof(hash1));for (int i = 0; i < n; i++)scanf("%d", &num[i]);for (int i = 0; i < m; i++){scanf("%s", word[i]);int len = strlen(word[i]);int digits = 0;for (int j = 0; j < len; j++)digits = digits * 10 + kind[word[i][j] - 'a'] - '0'; for (int j = 0; j < n; j++){if (num[j] == digits){hash1[digits]++;break;}}}for (int i = 0; i < n; i++)printf("%d\n", hash1[num[i]]);}return 0;}
1 0
- hdu4287 Intelligent IME--哈希表
- 【STL】 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
- 程序员小笑话
- woj1537&&woj1538(递推)
- 三重积分题z=0,z=y,y=1和抛物柱面y=x^2,所围成的有限闭区域,∫∫∫ydxdydz
- 初学正则表达式
- 经典贪心:最短过桥时间
- hdu4287 Intelligent IME--哈希表
- [数据结构]MyString
- 数据处理工具类(求和,平均值,最大值,最小值。。。)
- 51nod 1246 罐子和硬币
- VPN中的密钥交换算法
- 【Light】[1213]Fantasy of a Summation
- ContentResolver查询系统音乐文件
- C#单例模式使用
- 错误:datanode无法启动