PS/BOJ
[백준] 10807. 개수 세기(c++)
backend 개발자 지망생
2025. 1. 19. 18:45
https://www.acmicpc.net/problem/10807
배열을 활용한 문제였다.
-100 ~ 100 까지를 배열의 인덱스에 저장하기 위해 100을 더한 값을 인덱스로 지정했다.
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, v;
cin >> n;
vector<int> arr(201);
int temp;
for (int i = 0; i < n; i++) {
cin >> temp;
arr[temp + 100]++;
}
cin >> v;
cout << arr[v + 100] << '\n';
return 0;
}