백준

14659번: 한조서열정리하고옴ㅋㅋ

bingual 2022. 2. 15. 20:54
반응형

 

 

 

 

 

 

풀이

 

기준값을 다음 값과 비교해서 기준값이 더 크다면 카운트 한뒤 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)