CPP71. 判断元素是否出现
描述
输入描述
输出描述
对每个询问,输出一行表示答案。示例1
输入:
5 3 1 2 3 4 5 5 4 6
输出:
yes yes no
C++ 解法, 执行用时: 18ms, 内存消耗: 1296KB, 提交时间: 2022-07-14
#include<bits/stdc++.h> using namespace std; int main(){ //write your code here...... int n,m,num; scanf("%d %d",&n,&m); set<int>a; for (int i=0;i<n;i++) { scanf("%d",&num); a.insert(num); } while (m--) { scanf("%d",&num); if (a.find(num) != a.end()) printf("yes\n"); else printf("no\n"); } return 0; }
C++ 解法, 执行用时: 18ms, 内存消耗: 1304KB, 提交时间: 2022-07-03
#include<bits/stdc++.h> using namespace std; int main(){ //write your code here...... int n,m,num; scanf("%d %d",&n,&m); set<int>a; for (int i=0;i<n;i++) { scanf("%d",&num); a.insert(num); } while (m--) { scanf("%d",&num); if (a.find(num) != a.end()) printf("yes\n"); else printf("no\n"); } return 0; }
C++ 解法, 执行用时: 19ms, 内存消耗: 1588KB, 提交时间: 2022-06-11
#include<bits/stdc++.h> using namespace std; int main(){ //write your code here...... int n,m,num; scanf("%d %d",&n,&m); set<int>a; for (int i=0;i<n;i++) { scanf("%d",&num); a.insert(num); } while (m--) { scanf("%d",&num); if (a.find(num) != a.end()) printf("yes\n"); else printf("no\n"); } return 0; }
C++ 解法, 执行用时: 20ms, 内存消耗: 1324KB, 提交时间: 2022-08-06
#include<bits/stdc++.h> using namespace std; int main(){ //write your code here...... int n,m,num; scanf("%d %d",&n,&m); set<int>a; for (int i=0;i<n;i++) { scanf("%d",&num); a.insert(num); } while (m--) { scanf("%d",&num); cout<<(a.find(num)==a.end()?"no":"yes")<<"\n"; } return 0; }
C++ 解法, 执行用时: 23ms, 内存消耗: 1852KB, 提交时间: 2022-07-28
#include<bits/stdc++.h> #include<map> using namespace std; int main(){ //write your code here...... map<int,string>map1; int m,n; scanf("%d %d\n",&n,&m); int x; while(n--) { scanf("%d ",&x); map1.insert(pair<int,string>(x,"yes")); } map<int,string>::iterator it; while(m--) { scanf("\n%d",&x); it=map1.find(x); cout<<(it==map1.end()?"no":"yes")<<"\n"; } return 0; }