离散题目1
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
创建一个函数,以确定一个整数值是否包含在集合中。
Input
多组输入。
首先输入集合的元素数n<=100000。
接下来的一行输入n 个整数0<=ai<=n。
接下来的一行输入一个整数 0<=b<=n。
Output
(一组答案占一行),如果存在就输出true,如果不存在就输出false.
Example Input
5
1 2 3 4 5
4
Example Output
true
#include<cstdio>
#include<set>
using namespace std;
int main()
{
int n;
set<int> a;
while(~scanf("%d", &n))
{
int i, num;
for(i = 0; i < n; i++)
{
scanf("%d", &num);
a.insert(num);//因为只要集合的元素出现一次就可以了,所以可以使用set
}
scanf("%d", &num);
if(a.count(num)) printf("true\n");//如果存在
else printf("false\n");//否则
a.clear();
}
return 0;
}