AOJ 0033 Balls
頻出典型アルゴリズムの演習問題としてよさげなやつ を上から順に解いていこう企画。
最初の問題は「AOJ 0033 Balls」
深さ優先探索って書いてあったけど、これでいいのかな。
import java.util.Scanner; public class Main { private static Scanner s = new Scanner(System.in); public static void main(String[] args) { int n = s.nextInt(); for(int i=0; i<n; i++) { int[] ballSet = nextInput(); System.out.println(isSortable(ballSet) ? "YES" : "NO"); } } public static boolean isSortable(int[] ballSet) { int bufB = 0; int bufC = 0; for(int ball : ballSet) { if(ball > bufB) { bufB = ball; } else if(ball > bufC) { bufC = ball; } else { return false; } } return true; } public static int[] nextInput() { int[] input = new int[10]; for(int i=0; i<10; i++) { input[i] = s.nextInt(); } return input; } }
isSortableという名前が気に食わない。