您的位置:首页 > 其它

NYOJ 题目685 查找字符串(STL----map)

2013-08-22 19:11 309 查看

查找字符串

时间限制:1000 ms  |  内存限制:65535 KB

[align=center]难度:3[/align]
描述
小明得到了一张写有奇怪字符串的纸,他想知道一些字符串出现了多少次,但这些字符串太多了,他想找你帮忙,你能帮他吗?输入字符包括所有小写字母、‘@’、‘+’。
输入 第一行包含一个整数T(T<=100).表示测试数据组数。

接下来每组数据第一行包含两个整数n,m(n,m<100000),分别表示有n个字符串,小明要问你m次。

接下来n行,每行包含一个字符串,长度不大于15。

接下来m行,每行包含一个字符串,表示小明要问该串出现的次数。
输出 输出每组小明询问数串出现的次数。 样例输入
1
5 3
hello
it@is+so@easy
hello
ibelieveicanac
hello
hello
icannotacit
Giveup


 


样例输出


3


0


0

 

 

 

 

 

 

/***************************
# 2013-8-22 18:47:15
# Time: 140MS   Memory: 308KB
# Author: zyh
# Status: Accepted
***************************/

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>

using namespace std;

map<string,int> M;

int main()
{
int n,m,t;
char s[16];
string str;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
getchar();
while(n--){
gets(s);
str = s;
M[str]++;
}
while(m--){
gets(s);
str = s;
printf("%d\n",M[str]);
}
M.clear();
}
return 0;
}


 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: