Intelligent IME

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

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
 

Source

 
 //2017-09-29
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; int arr[N];
int book[];
char str[]; int change(char ch){
if('a' <= ch && ch <= 'c')return ;
if('d' <= ch && ch <= 'f')return ;
if('g' <= ch && ch <= 'i')return ;
if('j' <= ch && ch <= 'l')return ;
if('m' <= ch && ch <= 'o')return ;
if('p' <= ch && ch <= 's')return ;
if('t' <= ch && ch <= 'v')return ;
if('w' <= ch && ch <= 'z')return ;
} int main()
{
int T, n, m;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++){
scanf("%d", &arr[i]);
book[arr[i]] = ;
}
for(int i = ; i < m; i++){
scanf("%s", str);
int tmp = ;
for(int j = ; str[j] != '\0'; j++){
tmp *= ;
tmp += change(str[j]);
}
//printf("%s -> %d\n", str, tmp);
book[tmp]++;
}
for(int i = ; i < n; i++){
printf("%d\n", book[arr[i]]);
}
} return ;
}

最新文章

  1. [issue] [iOS 10] 升级后无法真机测试 Could not find Developer Disk Image
  2. HttpClient示例
  3. 我的Linux书架
  4. ios 中的block应用
  5. 项目源码--Android本地音乐播放器
  6. 使用Qt实现简单的图片预览效果 good
  7. Svg图片在asp网站上的使用
  8. 关于通过addClass与removeClass用jquery控制有良好兼容的CSS3样式
  9. Arduino入门学习
  10. h5标签基础 table表格标签
  11. JavaScript对象原型写法区别
  12. Android自定义View的套路
  13. 爬虫豆瓣top250项目-开发文档
  14. Python是如何进行内存管理
  15. 文本编辑器vim和gedit
  16. 七天学会ASP.NET MVC ——深入理解ASP.NET MVC
  17. 基于redis的延迟消息队列设计(转)
  18. MVC与单元测试实践之健身网站(七)-日程与打卡
  19. 【转】Visual Studio——多字节编码与Unicode码
  20. twitter ads_campaign management

热门文章

  1. 第二十一节:Java语言基础-关键字,标识符,注释,常量和变量,运算符
  2. koa-static与react-create-app搭配的路径
  3. 《JavaScript面向对象编程指南》读书笔记②
  4. web API简介(一):API,Ajax和Fetch
  5. OpenStack-Ocata版+CentOS7.6 云平台环境搭建 — 8.仪表盘 Dashboard(horizon)安装配置
  6. [git] 基本原理
  7. MyBatis核心接口和类
  8. python实现桶排序算法
  9. 机器学习(Machine Learning)算法总结-决策树
  10. Rip配置