1680: 查找1
Time Limit: 1 Sec Memory Limit: 128 MB
[Submit][Status][Web Board]
Description
给你一个长度是n的序列A,然后,有m次询问,每次询问是一个数字X,请你告诉我X在序列A中是否存在,存在输出YES,否则输出NO
Input
第一行 ,n,m,(n,m<=100000)
第二行n个数(每个数<=1000)
第三行m个数
Output
输出答案
Sample Input
5 4
2 5 4 3 5
2 5 8 9
Sample Output
YES
YES
NO
NO
HINT
Source
AC代码:
#include <stdio.h>
#include <set>
using namespace std;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
set<int>date;
int x,y;
for(int i = 0; i < n; i++)
{
scanf("%d",&x);
date.insert(x);
}
while(m--)
{
scanf("%d",&y);
if(date.count(y))
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
/*
总结:
set是STL中的一种容器,输入的相同的数据只会保留一个
(即容器中保留的不会有两个以上相同数据)
而且输入进去后会自动从小到大排序
1.头文件:
#include <set>
using namespace std;
2.定义:
set<数据类型>名字
3.插入数据:
比如插入数据x
名字.insert(x);
4.常用于查找某个值是否存在
名字.count(x);
存在会返回1,否则0;
*/