반응형
풀이
기준값을 다음 값과 비교해서 기준값이 더 크다면 카운트 한뒤 result값보다 cnt값이 더크다면 result는 cnt값이 된다. 그렇지 않다면 카운트를 초기화하고 과정을 반복한다.
자바
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int result = 0;
int cnt = 0;
int check = 0;
for (int i : arr) {
if (i >= check) {
check = i;
cnt = 0;
}
if (i < check) {
cnt++;
if (result < cnt)
result = cnt;
}
}
System.out.println(result);
}
}
파이썬
n = int(input())
h = list(map(int, input().split()))
result = 0
cnt = 0
check = 0
for i in h:
if i >= check:
check = i
cnt = 0
if i < check:
cnt+=1
if result < cnt:
result = cnt
print(result)
'백준' 카테고리의 다른 글
1789번: 수들의 합 (0) | 2022.02.16 |
---|---|
13305번: 주유소 (0) | 2022.02.15 |
16435번: 스네이크버드 (0) | 2022.02.15 |
17224번: APC는 왜 서브태스크 대회가 되었을까? (0) | 2022.02.15 |
14487번: 욱제는 효도쟁이야!! (0) | 2022.02.15 |