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 ;
}

HDU4287的更多相关文章

  1. hdu4287 字典树

    #include<stdio.h> #include<string.h> #include<stdlib.h> #define maxn 10 struct tri ...

  2. hdu4287 水题

    题意:          水题,就是给你一些单词,和一些按键记录,问打出下面的那些单词,每一个按键记录一共按了多少次. 思路:       直接把每个单词的每一位转换成数字,然后再把每个单词转换的数字 ...

随机推荐

  1. NET Core微服务之路:再谈分布式系统中一致性问题分析

    前言 一致性:很多时候表现在IT系统中,通常在分布式系统中,必须(或最终)为多个节点的数据保持一致.世间万物,也有存在相同的特征或相似,比如儿时的双胞胎,一批工厂流水线的产品,当然,我们不去讨论非IT ...

  2. spring boot开发笔记——mybatis

    概述   mybatis框架的优点,就不用多说了,今天这边干货主要讲mybatis的逆向工程,以及springboot的集成技巧,和分页的使用   因为在日常的开发中,当碰到特殊需求之类会手动写一下s ...

  3. 详解Android中的四大组件之一:Activity详解

    activity的生命周期 activity的四种状态 running:正在运行,处于活动状态,用户可以点击屏幕,是将activity处于栈顶的状态. paused:暂停,处于失去焦点的时候,处于pa ...

  4. H5的Page Visibility API

    概述 哈哈,又学了一个H5的API.今天突然对动态获取网页的选中状态很感兴趣,然后去查了下,发现真的有个API控制它--Page Visibility API.于是把学到的东西记录下来,供以后开发时参 ...

  5. Zabbix-3-自定义脚本获取数据

    通过在agent中加入脚本,来获取数据,生成图形

  6. Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instance in another process or thread is using this directory.

    1. 问题现象 启动 kafka 时报错:Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instance in an ...

  7. IDEA的maven配置

    刚接触maven的时候,也知道maven目录下有个setting文件可以设置远程maven库的地址,但自己实践的时候,发现setting文件的地址都被注释掉了,但是jar包还是能成功下载下来,那这个下 ...

  8. app测试自动化之定位元素

    app中元素定位是通过uiautomatorviewer来查看,这个是android sdk中自带的一个工具,可以在sdk家目录的tools下找到: 双击打开之后,点击第二个按钮即可把手机当前界面的元 ...

  9. ABP实践(3)-ASP.NET Core 2.x版本(从创建实体到输出api)简单实现商品列表及增删改

    项目基于前两篇文章. 本章创建一个简单版的商品管理后台api,用到EF Core用code fist迁移数据创建数据库. 创建Goods实体 在领域层xxx.Core项目[新建文件夹Goods;文件夹 ...

  10. FF笔试题整理

    一.选择题 1.怎样能唯一确定一颗二叉树? [解析] 只要知道中序遍历顺序,再加上其余两个遍历中任意一个都可以唯一确定一个二叉树.如果不知道中序遍历顺序,则无法确定. [反例] A-B-C,A是跟,B ...