Intelligent IME

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1348    Accepted Submission(s): 685

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

题意:根据题目中给的。小写字母都可以对应成一个数字。。先输入一个n,一个m,接下去输入n个号码,m个小写字母组成的号码。要求出n个号码中每个在m个小写字母中出现的次数。。

思路:。由于只有6位数。直接开个100W的数组标记每个号码就可以了。。 每次小写字母转换成的号码就在该号码加一。最后输出就可以了。。

代码:

#include <stdio.h>
#include <string.h>
#include <map>
#include <string>
using namespace std; int t;
int n, m;
int vis[1000];
int sb[5005];
int hash[1000005];
int main() {
vis['a'] = vis['b'] = vis['c'] = 2;
vis['d'] = vis['e'] = vis['f'] = 3;
vis['g'] = vis['h'] = vis['i'] = 4;
vis['j'] = vis['k'] = vis['l'] = 5;
vis['m'] = vis['n'] = vis['o'] = 6;
vis['p'] = vis['q'] = vis['r'] = vis['s'] = 7;
vis['t'] = vis['u'] = vis['v'] = 8;
vis['w'] = vis['x'] = vis['y'] = vis['z'] = 9;
scanf("%d", &t);
while (t --) {
memset(hash, 0, sizeof(hash));
memset(sb, 0, sizeof(sb));
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i ++)
scanf("%d", &sb[i]);
getchar();
for (int i = 0; i < m; i ++) {
char sbbb[10];
int num = 0;
gets(sbbb);
for (int j = 0; j < strlen(sbbb); j ++)
num = num * 10 + vis[sbbb[j]];
hash[num] ++;
}
for (int i = 0; i < n; i ++)
printf("%d\n", hash[sb[i]]);
}
return 0;
}

最新文章

  1. MongoDB【第二篇】MongoDB逻辑与物理存储结构
  2. AOP 面向切面编程, Attribute在项目中的应用
  3. mysql在同一个表上查询和更新
  4. Deep Learning(1)-Introduction学习总结
  5. WCF客户端承载
  6. 第二十章 数据访问(In .net4.5) 之 使用LINQ
  7. makefile 中 $@ $^ %&lt; 使用
  8. 使用Understand获取某个函数(方法)的静态度量指标
  9. web安全普及:通俗易懂,如何让网站变得更安全?以实例来讲述网站入侵原理及防护。
  10. 【集美大学1411_助教博客】团队作业9——测试与发布(Beta版本)
  11. Python循环列表删除元素问题
  12. C#中yield的使用
  13. Beta版本敏捷冲刺每日报告——Day2
  14. 用python对比两张图片的不同
  15. Redis5种常用的数据结构
  16. 内建模块collections的使用
  17. leetcode979
  18. Android Java中的一些使用例子
  19. MongoDB NoSQL 常用指令
  20. Linux学习 : Socket 网络编程入门

热门文章

  1. 第七篇、Nginx Install On Mac
  2. 用css3实现鼠标移进去当前亮其他变灰
  3. JDK和JRE的区别?
  4. Android中AppWidget的分析与应用:AppWidgetProvider .
  5. iscc2016-好长的字符串
  6. loadView与viewDidLoad不同 &amp;&amp; loadView学习总结
  7. ha666_go运行环境配置
  8. myeclipse spket spket-1.6.23.jar 破解安装教程
  9. ubuntu 查本机 ip地址的命令是什么, 详细信息的?
  10. COJ 0047 20702最大乘积