c/c++查询M个数在N数组中出现的次数

#include
const int maxn = 100001;

int hashTable[maxn] = { 0 };

int main() {
	int n, m, x;
	scanf_s("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &x);
		hashTable[x]++;
	}

	for (int i = 0; i < m; i++) {
		scanf_s("%d", &x);
		printf("%d\n", hashTable[x]);
	}

	return 0;
}
输入:
4 2
1 2 3 2
2
输出:2
输入:4
输出:0

你可能感兴趣的:(c++数据结构)