https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3093
困難度 ★ 判斷數列是否遞增或遞減(同個迴圈判斷分開檢測)必須通過下列這項測資 1 1 2 3 4 6 5 7 8 9 10
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
System.out.println("Lumberjacks:");
while (n-- != 0) {
int arr[] = new int[10], ary[] = new int[10], count1 = 0,count2=0;
for (int i = 0; i < 10; i++) {
arr[i] = scn.nextInt();
ary[i] = arr[i];
}
Arrays.sort(arr);
for (int i = 0, j = 9; i < 10; i++, j--) {
if (arr[i] == ary[i])
count1++;
else if(arr[i] == ary[j])
count2++;
else
break;
}
if (count1 == 10||count2 == 10)
System.out.println("Ordered");
else
System.out.println("Unordered");
}
}
/*
題目:Q11942 : Lumberjack Sequencing
作者:1010
時間:西元 2016 年 7 月 */
}