Description

Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message “Play Me”. He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is connected to the terminal next to him. After pressing a Play button a rough voice starts playing from the tape:

“Listen up Smith. As you can see, you are in pretty tough situation and in order to escape, you have to solve a puzzle.

You are given N strings which represent words. Each word is of the maximum length L and consists of characters ‘a’-‘e’. You are also given M strings which represent patterns. Pattern is a string of length  ≤  L and consists of characters ‘a’-‘e’ as well as the maximum 3 characters ‘?’. Character ‘?’ is an unknown character, meaning it can be equal to any character ‘a’-‘e’, or even an empty character. For each pattern find the number of words that matches with the given pattern. After solving it and typing the result in the terminal, the key will drop from the ceiling and you may escape. Let the game begin.”

Help Smith escape.

Input

The first line of input contains two integers N and M (1 ≤ N ≤  100 000, 1 ≤ M ≤  5000), representing the number of words and patterns respectively.

The next N lines represent each word, and after those N lines, following M lines represent each pattern. Each word and each pattern has a maximum length L (1 ≤ L ≤ 50). Each pattern has no more that three characters ‘?’. All other characters in words and patters are lowercase English letters from ‘a’ to ‘e’.

Output

Output contains M lines and each line consists of one integer, representing the number of words that match the corresponding pattern.

Example input

3 1
abc
aec
ac
a?c

output

3

题目大意

先给定m个字符串,再给一个含有’?’(至多包含3个)的字符串,’?’可以替换成字符’a’~’e’,或者直接去掉,然后在m个字符串中查找有多少个可以实现完全匹配。

解题思路

暴力

代码实现

#include <iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
using namespace std;
map<string,int>mp;
set<string>ss;
string str;
void dfs(string st)
{int len=st.size(),i=0;while(st[i]!='?'&&i<len) i++;if(i==len){ss.insert(st);return ;}for(char ch='a'; ch<='e'; ch++){st[i]=ch;dfs(st);}dfs(st.substr(0,i)+st.substr(i+1,len-1));
}
int main()
{ios_base::sync_with_stdio(false);int n,m;cin>>m>>n;mp.clear();for(int i=0; i<m; i++){cin>>str;mp[str]++;}for(int i=0; i<n; i++){int ans=0;ss.clear();cin>>str;dfs(str);set<string>::iterator it;for(it=ss.begin(); it!=ss.end(); it++){if(mp[*it]>0)ans+=mp[*it];}cout<<ans<<endl;}return 0;
}

Bubble Cup X - Finals [Online Mirror] G. Bathroom terminal(STL)相关推荐

  1. Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2) J. Robot Factor

    翻译: 你已经收到了Bubble机器人的数据.你知道你的任务是制造工厂设施,但在你开始之前,你需要知道工厂有多大,有多少房间.当你查看数据时,你会发现你有这个结构的尺寸,它是矩形的:N x M. 然后 ...

  2. Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2) J. Robot Factory

    传送门 题意: 给你一个矩阵,矩阵中的每一个数的二进制串可以表示出该位置周围的围墙信息,让你求出所有的房间大小. 思路: 建图,搜索,一气呵成. #include<iostream> #i ...

  3. Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca

    B. Bribes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/B De ...

  4. Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2) E. Array Game

    Array Game Link 题目大意: A l i c e Alice Alice 与 B o b Bob Bob ,从一个长度为 n n n 的数组中轮流从数组首部或尾部取数, A l i c ...

  5. Bubble Cup 12 - Finals [Online Mirror, unrated, Div. 1] F. Workout plan(优先队列)

    有一个人要锻炼 n 天,初始时战斗力为 k,每天都要达到 x[i] 才可以,每天都有一款饮料价格为 c[i],每一款饮料都可以让他的战斗力增加 A,问最少要花都少钱才能完成每天的计划,如果有一天不能输 ...

  6. 小G的项链(Manacher)

    我看网上也没有写这个题的,顺便写一下(可能是大佬都觉得太简单了 ) 链接:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO ...

  7. ITU-T G.8261 解读(一)

    前言 ITU-T G.8261标准是ITU-T组织在规定分组网络时起草的一份针对频率同步的文件.它规定了网络在传输数据的过程中不应该超过的最大的抖动与漂移值抖动与漂移的区别是什么?简而言之," ...

  8. Bubble Cup 8 finals D. Tablecity (575D)

    题意: (无输入,纯输出题) 一个城市用1000列2行的格子表示,一个小偷藏在城市的某一处. 在每一小时的开始, 在(X, Y)位置的小偷可以移动到 (X - 1, Y), (X + 1, Y),(X ...

  9. 2018 Multi-University Training Contest 3: G. Interstellar Travel(凸包)

    题意:给你平面上n个点,第一个点一定在(0, 0),第n个点的y坐标一定为0,除此之外中间所有点的x坐标一定大于0且小于最后一个点的x坐标,你从一号点开始出发,中间从第i个点到第j个点必须满足xj&g ...

最新文章

  1. 在PC机上运行的linux系统是,Docker Desktop如何在Windows计算机上运行linux容...
  2. 用keil烧写现成的hex文件
  3. memcached 分布式 一致性hash算法demo
  4. mysql user_tab_cols_最新Oracle 和 mysql 的对比参照----开发篇(转)
  5. boost::container模块实现插入和放置的测试程序
  6. 安全看得见,阿里云性能监控 ARMS 全真3D拓扑实现一“屏”了然
  7. iOS中XML解析 (一) TBXML (实例:打印xml内容及存储到数组)
  8. 怎么扩展磁盘_电脑怎么增加C盘空间 小白教你不花钱增加C盘空间
  9. upupw启动mysql失败,Can't init tc log
  10. 赚钱有捷径吗?为什么有的人赚钱很容易
  11. 安装webpack命令环境
  12. 移动开发语言Swift
  13. JavaMaven【二、目录结构HelloMaven】
  14. 【科来】网络异常行为分析学习笔记
  15. PS命令各字段英文全称
  16. VMware使用技巧之“快照”+“克隆”
  17. STC15F104W 使用 315/433 MHz 超再生模块发送/接收数据
  18. 收集的13个杀毒软件和安全防护软件(有图哦)
  19. 电脑上的ofd格式文件如何打开呢_ofd文件怎么打开用什么软件
  20. oppo便签误删怎么办_OPPO手机便签删除了怎么恢复?有无需登录云端就可以恢复的备忘录软件吗...

热门文章

  1. Quartes彻底卸载步骤(笔记)
  2. 婚后.........
  3. CPU处理器辨识 盒装处理器方式 内存条
  4. 闪电网络RSMC协议技术原理----从微支付通道到RSMC(序列到期可撤销合约)
  5. 小学阶段怎么练习英语口语?三个练习方法分享!
  6. 惠普在华扩招千名新员工
  7. linux命令-mv命令
  8. 十几年老Java咳血推荐,你薪资涨一波没毛病!小AD以为我端午都干嘛去了?
  9. Linux EAS介绍
  10. 追女生不需要花费太多,只要掌握这五个技巧