백준/BRONZE
[백준 10807번][C++] 개수 세기
퍼펙트코딩
2022. 8. 30. 23:29
728x90
반응형
#include <iostream>
using namespace std;
int main() {
//-100 ~ 100 의 수의 개수를 담기위한 201이상 크기의 배열
int list[204]{ 0, };
int test;
cin >> test;
int input;
//수 입력받고 그에맞는 INDEX의 수 증가
for (int i = 0;i < test;i++) {
cin >> input;
//음수일 때는 201을 더해주어 INDEX 100이상으로 취급
if (input < 0) {
input += 201;
}
list[input]++;
}
//타겟수 입력받고 그 INDEX의 수 출력
cin >> input;
if (input < 0) {
input += 201;
}
cout << list[input];
}
728x90
반응형