离散题目1
2017-05-26 17:50
225 查看
离散题目1
Time Limit: 1000MS Memory Limit: 65536KBSubmit 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
think:直接遍历一遍寻找相对应的元素计科,不会超时。
#include <bits/stdc++.h> using namespace std; int main() { int m, n; int a[100005]; while(cin>>m) { for(int i = 0; i < m; i++) cin>>a[i]; cin>>n; int flag = 0; for(int i = 0; i < m; i++) { if(a[i] == n) { flag = 1; break; } } if(flag) cout<<"true"<<endl; else cout<<"false"<<endl; } return 0; }