题解 | #判断元素是否出现#
判断元素是否出现
https://www.nowcoder.com/practice/0787459e92bc4360ba48b094b7f21577
#include<bits/stdc++.h> #include <iostream> using namespace std; int main(){ //write your code here...... int n, m; cin >> n >> m; map<int, int>a; for (int i = 0; i < n; ++i) { int num; cin >> num; a[num]++; } int i = 0; while (i < m) { int k; cin >> k; if (a.count(k)) cout << "yes" << endl; else cout << "no" << endl; ++i; } return 0; }
map使用count区分有没有出现。