散列查找(哈希表Hash)
利用内置结构
unordered
Note:注意是Hashtable,而不是Hashtable[MAXN]
题目:
解答:
/* ------------------------------------------------- Author: wry date: 2022/3/2 18:12 Description: Hash ------------------------------------------------- */ #includeusing namespace std; const int MAXN = 100+10; int arr[MAXN]; unordered_map<int,bool>HashTable; //哈希表构建时,不用加[MAXN],int表示索引,bool是值,操作和数组相似 int main() { int n,m,k; while (cin>>n) { for (int i=0;i ) { cin >> arr[i]; HashTable[arr[i]] = true; } cin >> m; while (m--) { cin >> k; if (HashTable[k]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } } return 0; }