๋ฐ์ํ
https://www.acmicpc.net/problem/17608
์ฝ๋
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int[] arr = new int[N];
for(int i=0; i<arr.length; i++)
arr[i] = scan.nextInt();
int count = 1; // ์ค๋ฅธ์ชฝ์์ ๋ณด์ด๋ ๊ฐฏ์
int maxHeight = arr[arr.length-1]; // ๊ฐ์ฅ ๋์ ๋ง๋๊ธฐ์ ๋์ด
for(int i=arr.length-2; i>=0; i--) {
if(arr[i] > maxHeight) {
count ++;
maxHeight = arr[i];
}
}
System.out.println(count);
scan.close();
}
}
ํ์ด
์ค๋ฅธ์ชฝ ๋ถํฐ ๋น๊ตํด๊ฐ๋ฉด์ ๋์ด๊ฐ ๊ฐ์ฅ ๋์๊ฑฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ๋น๊ต๋ฅผ ํ๊ณ ๋ณด์ด๋๊ฑฐ ์นด์ดํธํด์ฃผ๋ฉด ๋.
๋์ด๊ฐ ์ค๋ฅธ์ชฝ๊บผ๋ณด๋ค ๋์๊ฒ ๋์ค๋ฉด ๋์๊ฑฐ๋ก ๋ณ๊ฒฝํด์ค์ผํจ.
Scanner / BufferedReader ์ ๋ฐ๋ผ ๋ฉ๋ชจ๋ฆฌ, ์๊ฐ ์ฐจ์ด๊ฐ ์ข ๋๋ค.
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 1940๋ฒ: ์ฃผ๋ชฝ(์ํ, ์ ๋ ฌ) (0) | 2020.04.23 |
---|---|
[๋ฐฑ์ค] 9012๋ฒ: ๊ดํธ(์คํ) (0) | 2020.04.19 |
[๋ฐฑ์ค] 5533๋ฒ: ์ ๋ํฌ(๊ตฌํ) (0) | 2020.04.10 |
[๋ฐฑ์ค] 5032๋ฒ: ํ์ฐ ์๋ฃ(๊ตฌํ, ์ํ) (0) | 2020.04.10 |
[๋ฐฑ์ค] 3054๋ฒ: ํผํฐํฌ ํ๋ ์(๊ตฌํ) (0) | 2020.04.10 |
๋๊ธ