Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature.

There are n

files on hard drive and their names are f1,f2,…,fn. Any file name contains between 1 and 8

characters, inclusive. All file names are unique.

The file suggestion feature handles queries, each represented by a string s

. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s

) and suggest any such file name.

For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2

(two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18".

Input

The first line of the input contains integer n

(1≤n≤10000

) — the total number of files.

The following n

lines contain file names, one per line. The i-th line contains fi — the name of the i-th file. Each file name contains between 1 and 8

characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique.

The following line contains integer q

(1≤q≤50000

) — the total number of queries.

The following q

lines contain queries s1,s2,…,sq, one per line. Each sj has length between 1 and 8

characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.').

Output

Print q

lines, one per query. The j-th line should contain the response on the j-th query — two values cj and tj

, where

  • cjis the number of matched files for the j-th query, tj is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any.
4
test
contests
test.
.test
6
ts
.
st.
.test
contes.
st
Output

Copy
1 contests
2 .test
1 test.
1 .test
0 -
4 test.

题意:有n个字符串,q次查询,输出与之匹配字符串的个数,并输出任意一个字符串;

题解:由于每个字符串的长度<=8,所以我们可以把该字符串的字串全部存进map,并记录该字符串的位置;

直接输出就可以啦;

 #include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
int m,n;
map<string,int>::iterator it;
map<string,int>mp;//存储所有字符串的字串
map<string,int>pos;//存储字符串的位置
void Substr(string str,int num)
{
string arr;
map<string,int>mp1;
for(int i=;i<str.size();i++)
{
for(int j=;j<=str.size();j++)
{
arr=str.substr(i,j);
if(!mp1.count(arr))
{
mp1[arr]++;
pos[arr]=num;
}
}
}
for(it=mp1.begin();it!=mp1.end();it++)
{
mp[it->first]++;
//cout<<it->first<<endl;
}
}
int main()
{
string s,str;
cin>>m;
map<int,string>kp;//记录原串
for(int i=;i<m;i++)
{
cin>>str;
kp[i]=str;
Substr(str,i);//求子串
}
cin>>n;
while(n--)
{
cin>>s;
if(mp.count(s))
{
cout<<mp[s]<<" "<<kp[pos[s]]<<endl;
}
else
{
cout<<""<<" "<<"-"<<endl;
}
}
}

BerOS File Suggestion(stl-map应用)的更多相关文章

  1. BerOS File Suggestion(字符串匹配map)

    BerOS File Suggestion(stl-map应用) Polycarp is working on a new operating system called BerOS. He asks ...

  2. stl::map之const函数访问

    如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...

  3. hdu4941 Magical Forest (stl map)

    2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit ...

  4. [CareerCup] 13.2 Compare Hash Table and STL Map 比较哈希表和Map

    13.2 Compare and contrast a hash table and an STL map. How is a hash table implemented? If the numbe ...

  5. STL MAP及字典树在关键字统计中的性能分析

    转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...

  6. POJ 3096 Surprising Strings(STL map string set vector)

    题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...

  7. STL MAP 反序迭代

    ITS_NOTICE_MAP::reverse_iterator it = noticeMap.rbegin(); for ( ; it != noticeMap.rend(); ++it ) { I ...

  8. 泛型Binary Search Tree实现,And和STL map比较的经营业绩

    问题叙述性说明: 1.binary search tree它是一种二进制树的.对于key值.比当前节点左孩子少大于右子. 2.binary search tree不是自平衡树.所以,当插入数据不是非常 ...

  9. Dictionary,hashtable, stl:map有什么异同?

    相同点:字典和map都是泛型,而hashtable不是泛型. 不同点:三者算法都不相同 Hashtable,看名字能想到,它是采用传统的哈希算法:探测散列算法,而字典则采用的是散列拉链算法,效率较高, ...

随机推荐

  1. centos7部署openvpn-2.4.6

    一.环境说明 返回主机的IP地址 # ip a | grep "scope global" | awk -F'[ /]+' '{print $3}' | head -1 [root ...

  2. [UE4]增加机器人

    一.新增蓝图继承自Shooter名为AIShooter.玩家角色也是继承自Shooter. 二.使用AIMoveTo追踪玩家.玩家控制的角色调用这个方法没反应. 三.关卡中添加组件NavMeshBou ...

  3. Java基础知识_毕向东_Java基础视频教程笔记(26 反射)

    Java反射机制: 是在运行状态中,对于任意一个类(class)文件,都能够知道这个类的所有属性和方法,对于任意一个对象,都能够调用它的任意一个方法和属性.这种动态获取的信息以及动态调用对象的方法的功 ...

  4. prvReadAsyncOperation

    prvReadAsyncOperation privilege is the Read privilege for System Job Entity (Role Customizationtab). ...

  5. 第10章 网络安全(3)_安全套接字层SSL

    4. 安全套接字层 4.1 安全套接字层(SSL)和传输层安全(TLS) (1)SSL/TLS提供的安全服务 ①SSL服务器鉴别,允许用户证实服务器的身份.支持SSL的客户端通过验证来自服务器的证书, ...

  6. C#语言基础知识

    一. string i_str = "321"; string 型,强制转换成 int 型 int i_int1 = int.parse(i_str); string 型,强制转换 ...

  7. 02 Linux常见命令

    GUI图形界面 图形界面对于我们的Linux系统来说就是一个单独的软件程序,可以安装也可以不用安装: 我们常见的Linux下的常用图形软件为Gnome.KDE.XFce: GLI命令界面 Linux常 ...

  8. 点击复制内容到剪切板(clipboard)

    clipboard官方文档:https://clipboardjs.com/ 安装: 1.用npm:npm install clipboard --save 2.下载:https://github.c ...

  9. android 开发 实现多个动态权限的方法(并且兼容6.0以下的版本权限授权)

    android开发权限授权因为版本的不同有不同的授权方式,6.0以下的版本使用的是在注册表中添加权限的静态授权(这种授权权限提示只会出现在app安装的时候),而6.0以上(包含6.0)就需要动态授权的 ...

  10. 制作签名jar放置到前端资源目录下

    给jar包打签名keytool -genkey -keystore myKeystore -alias jwstest查看签名信息jarsigner -keystore myKeystore data ...