题解 | #矩阵查数#C++暴力遍历哈希表解法
矩阵查数
https://www.nowcoder.com/practice/dd5b5b2df5f84bae9b26c99a0a8f8660
#include <iostream> #include <unordered_map> using namespace std; int main() { int m=0; int n=0; cin>>m; cin>>n; int i=0; int j=0; unordered_map<int,int> hash; for(i=0;i<m;i++) { for(j=0;j<n;j++) { int a=0; cin>>a; if(hash.count(a)==0) { hash[a]=1; } else { hash[a]++; } } } int k=0; cin>>k; if(hash.count(k)==0) { cout<<"false"; } else { cout<<"true"; } return 0; }