1. up이 true인 상태에서 down이 확인되면 볼록 count++
2. 볼록 체크 시, up & down false로 초기화
- 제목
Counting Peaks of Infection
- 조건
시간 제한 : 1 초
메모리 제한 : 1024 MB
- 문제
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 the positive cases.
Here, the number of peaks is the number of days on which the number of positive cases reported is more than both of the day before and the next day.
As the PCR tests started before the disease started spreading in the city, the number of positive cases is zero on the first day. The last reported day is not counted as a peak. No two consecutive days have the same number of positive cases.
- 입력
The input consists of multiple datasets. Each dataset is in the following format.
n
v1 ... vn
n is the number of days on which the numbers of positive cases are reported (3 ≤ n ≤ 1000). vi is the number of positive cases on the i-th day, an integer between zero and 1000, inclusive. Note that v1 is zero, and vi ≠ vi+1 for 1 ≤ i < n, as stated above.
The end of the input is indicated by a line containing a zero. The input consists of at most 100 datasets.
- 출력
For each dataset, output the number of peaks in a line.
예제 입력1 | 예제 출력1 |
3 0 1000 0 5 0 1 2 0 1 3 0 1 2 7 0 1 0 1 8 7 6 11 0 4 3 7 6 10 7 8 4 6 10 0 |
1 1 0 2 4 |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <vector>
using namespace std;
#define endl '\n'
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main() {
fastio;
int sz, curr, prev;
bool up = false, down = false;
while(true){
cin >> sz;
if(sz == 0) break;
int upDown = 0;
for(int n = 0 ; n < sz ; n++){
cin >> curr;
if(n != 0){
if(prev < curr && n != 0){
up = true;
}
else if (prev > curr){
down = true;
if(up && down){
upDown++;
up = down = false;
}
}
}
prev = curr;
}
cout << upDown << endl;
}
return 0;
}
'Problem Solving > BaekJoon' 카테고리의 다른 글
[BOJ/백준] 16562 - 친구비 (0) | 2022.09.04 |
---|---|
[BOJ/백준] 25270 - 99 Problems (0) | 2022.09.04 |
[BOJ/백준] 25311 - UCPC에서 가장 쉬운 문제 번호는? (0) | 2022.09.02 |
[BOJ/백준] 17298 - 오큰수 (0) | 2022.09.02 |
[BOJ/백준] 14500 - 테트로미노 (0) | 2022.09.02 |