※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 25527번 문제인 Counting Peaks of Infection이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/25527
25527번: Counting Peaks of Infection
For the new infectious disease, COVID-99, numbers of new positive cases of PCR tests conducted in the city are reported daily. You are requested by the municipal public relations department to write a program that counts the number of the peaks so far of t
www.acmicpc.net
주어지는 i일째의 감염자 수를 v[i]라 할 때, v[i-1] < v[i] < v[i+1]을 만족하는 2 이상 N-1이하의 i의 개수를 세는 것으로 peak의 개수를 구할 수 있다.
반복문을 이용해 위 내용을 구현해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int N;
int arr[1000];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
while (N) {
int cnt = 0;
for (int i = 0; i < N; i++) cin >> arr[i];
for (int i = 1; i < N - 1; i++) {
if (arr[i - 1]<arr[i] && arr[i]>arr[i + 1]) cnt++;
}
cout << cnt << '\n';
cin >> N;
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 24296 // C++] ЛИНИЯ (0) | 2022.11.11 |
---|---|
[BOJ 25278 // C++] Terraforming (0) | 2022.11.11 |
[BOJ 2228 // C++] 구간 나누기 (0) | 2022.11.11 |
[BOJ 24309 // C++] РАВЕНСТВО (0) | 2022.11.11 |
[BOJ 11008 // C++] 복붙의 달인 (0) | 2022.11.10 |