No Rules Rules

숫자 카드 2 (feat. 백준, 10816번) 본문

생활/코테

숫자 카드 2 (feat. 백준, 10816번)

개발하는 완두콩 2022. 8. 3. 12:35
728x90
반응형

숫자 카드 2
https://www.acmicpc.net/problem/10816

반응형
// woohyeon.kim
// https://www.acmicpc.net/problem/10816
#include <iostream>
#include <map>
using namespace std;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	register int N, M;
	map<int, int> ans;
	cin >> N;
	for (register int i = 0, v; i < N; ++i)
		cin >> v, ++ans[v];
	cin >> M;
	for (register int i = 0, v; i < M; ++i) {
		cin >> v;
		if (ans.find(v) != ans.end())
			cout << ans[v];
		else
			cout << 0;
		cout << " ";
	}
	return 0;
}
// *&)*@*

자료구조 map을 이용하여 입력받은 정수형을 key로 갖고 그 횟수를 올려줍니다.

728x90
반응형
Comments