HrbustOJ 1987 逃课的孩子

逃课的孩子

Time Limit: 1000 MS Memory Limit: 32768 K

Total Submit: 740(135 users) Total Accepted: 156(97 users) Rating: Special Judge: No

Description

今天fribbi的室友们又逃课了,秉着不能互相卖队友的原则,他们选择玩游戏。他们让fribbi替他们去点名,可是fribbi的室友们只告诉了fribbi他需要去新主楼点名,没说哪个教室。不过还好fribbi有个扫描仪,当他进入到教室,可是很快扫描一下老师的点名册里有没有他室友们的名字。

要知道今天是周五上午,要上选修课,这意味这fribbi要跑好几个教室,去替不同的室友答到,而现在他需要做的是去检查所有教室的点名册里有没有他们室友们的名字,有谁的没有谁的。

现在他进入到了D406,扫描仪很快检查出有没有这些室友们的名字。

Input

有多组测试数据,对于每组输入数据,第一行输入两个正整数n和m,n代表点名册里的人数,m代表fribbi的室友个数。

接下来n行每行是一个字符串,代表点名册里的名字;再接下来m行每行是一个字符串,代表fribbi的室友的名字。

其中1≤n≤10000,1≤m≤10000 (fribbi的室友真的很多),字符串的长度均不超过10。

Sample Input

对于每组测试数据,输出占m行。分别表示这m个室友的名字是否出现过,出现过输出yes,否则输出no。

Sample Output

4 3
dream
mac
AmberG
wind
ShineCheng
AmberG
sunshine
Hint
no
yes
no

Source

2013级新生组队赛(11月)正式赛

题解

由map容器建立键值之间的对应关系,根据值去寻找键即可。
代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <map>
#include <cstring>
#include <cstdio>

using namespace std ;

int main(){
int n , m ;
while ( cin >> n >> m ){
map<string , bool> map_ ;
char str[15] ;
for ( int i = 0 ; i < n ; i ++ ){
scanf("%s" , str) ;
map_[str] = true ;
// cin >> str ;
// map_.insert(make_pair(str , true)) ;
}
for ( int i = 0 ; i < m ; i ++ ){
// cin >> str ;
scanf("%s" , str) ;
if ( map_[str] == true ){
// cout << "yes" << endl ;
puts("yes") ;
}else{
// cout << "no" << endl ;
puts("no") ;
}
}
}
return 0 ;
}