Created
June 6, 2018 07:05
-
-
Save hiramekun/6f544a190626e67c78aaff168799cb6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.Scanner; | |
class TroubleSort { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in))); | |
int T = scanner.nextInt(); | |
FOR: | |
for (int t = 0; t < T; t++) { | |
int N = scanner.nextInt(); | |
int[] V = new int[N]; | |
List<Integer> evens = new ArrayList<>(); | |
List<Integer> odds = new ArrayList<>(); | |
for (int n = 0; n < N; n++) { | |
if (n % 2 == 0) { | |
evens.add(scanner.nextInt()); | |
} else { | |
odds.add(scanner.nextInt()); | |
} | |
} | |
Collections.sort(evens); | |
Collections.sort(odds); | |
for (int n = 0; n < N; n++) { | |
if (n % 2 == 0) { | |
V[n] = evens.get(n / 2); | |
} else { | |
V[n] = odds.get(n / 2); | |
} | |
} | |
for (int i = 0; i < V.length - 1; i++) { | |
if (V[i] > V[i + 1]) { | |
System.out.println("Case #" + (t + 1) + ": " + i); | |
continue FOR; | |
} | |
} | |
System.out.println("Case #" + (t + 1) + ": OK"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment