给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过。
第一行两个整数 n 和m。
第二行n个正整数(1<=n<= 100000)
第三行m个整数(1<=m<=100000)
一共m行,若出现则输出YES,否则输出NO
4 2
2 1 3 4
1 9
YES
NO
所有数据都不超过10^8
//钻石的题目???
#include<bits/stdc++.h>
using namespace std;
int n,m;
bool f[100010];
int main(){
scanf("%d%d",&n,&m);
while(n--){
int x;
scanf("%d",&x);
f[x]=true;
}
while(m--){
int x;
scanf("%d",&x);
if(f[x])printf("YES\n");
else printf("NO\n");
}
return 0;
}
原文:http://www.cnblogs.com/codetogether/p/7066703.html