链接:https://ac.nowcoder.com/acm/contest/908/F
来源:牛客网
 

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

AFei has many cards. Each card has a number written on it. Now he wants to takes some out of his card and puts them in a box. And he wants to know whether the card with the number x was in the box. So he has the following two operations:

  • 0 x (It means to put a card with the number x in the box.)
  • 1 x   (It means to query if there is a card with the number x in the box.)

输入描述:

The first line of the input is an integer n (1 <= n <= 106), the number of operations. Next n lines  represent n operations, and two integers k ( k∈{0,1}) and x (0<=x<=109)  are separated by spaces on each line, as described above.

输出描述:

For each query, output one line "yes" if there is a card with the number x in the box, otherwise output one line "no".

示例1

输入

复制

5
0 1
1 2
0 2
1 3
1 2

输出

复制

no
no
yes

unordered_map学习https://blog.csdn.net/hk2291976/article/details/51037095

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<list>
#include<stack>
#include<queue>
#include<tr1/unordered_map>//在unordered_map之前加上tr1库名,
using namespace std::tr1;//与此同时需要加上命名空间
typedef long long ll;
unordered_map<int, int> mp;
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
    	int op,x;
    	scanf("%d%d",&op,&x);
    	if(op==0) mp[x]++;
    	else{
    		if(mp.find(x)!=mp.end()) printf("yes\n");
    		else printf("no\n");
		}
	}
	return 0;
}