Notice
Recent Posts
Recent Comments
Link
알고리즘 모음(C++)
백준 10807 - 개수 세기(C++) 본문
문제 링크입니다. https://www.acmicpc.net/problem/10807
배열 혹은 Map을 이용하면 쉽게 풀 수 있는 문제입니다.
기본 문제라고 할 수 있는 쉬운 문제입니다.
수가 주어졌을 때, 찾는 수가 얼마나 있는지를 구하는 문제입니다.
푸는 방법은 배열을 이용해 모든 수를 저장한 뒤, 배열 속에서 일치한 수를 찾는 방법이 있습니다.
다른 방법은 Map을 사용하면 더 쉽게 풀 수 있었습니다.
자세한 것은 코드를 참고해주세요
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <deque>
#include <stack>
#include <map>
#define pp pair<int, int>
#define F first
#define S second
using namespace std;
int N, M;
map<int, int> num;
int main() {
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N; i++){
int x;
cin >> x;
num[x]++;
}
cin >> M;
cout << num[M];
return 0;
}
질문 및 조언은 댓글을 남겨주세요
'백준' 카테고리의 다른 글
백준 2166 - 다각형의 면적(C++) (0) | 2023.02.01 |
---|---|
백준 5597 - 과제 안 내신 분..?(C++) (0) | 2023.01.31 |
백준 7453 - 합이 0인 네 정수(C++) (0) | 2023.01.28 |
백준 11652- 카드(C++) (0) | 2023.01.28 |
백준 10757 - 큰 수 A+B(C++) (0) | 2023.01.28 |