Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- // Collaborator: Dhipta Raditya Y
- public class UnlockNamronMothership {
- public static void main(String args[]) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int n = Integer.parseInt(reader.readLine());
- PasanganAB[] pasanganABs = new PasanganAB[n];
- for (int i = 0; i < n; i++) {
- String[] lines = reader.readLine().split(" ");
- int a = Integer.parseInt(lines[0]);
- int b = Integer.parseInt(lines[1]);
- pasanganABs[i] = new PasanganAB(a, b);
- }
- selectionSort(pasanganABs);
- printHasilSorting(pasanganABs);
- }
- private static void printHasilSorting(PasanganAB[] arr) {
- int n = arr.length;
- for (int i = 0; i < n; i++) {
- System.out.println(arr[i].a + " " + arr[i].b);
- }
- }
- private static void selectionSort(PasanganAB[] arr) {
- int n = arr.length;
- int minimumIndeks;
- for(int i=0; i < n; i++) {
- minimumIndeks = i;
- for(int j=i+1; j < n; j++){
- if (arr[j].hitungK() < arr[minimumIndeks].hitungK())
- minimumIndeks = j;
- else if(arr[j].hitungK() == arr[minimumIndeks].hitungK()){
- if(arr[j].compareTo(arr[minimumIndeks]) == -1) minimumIndeks = j;
- }
- }
- PasanganAB temp = arr[minimumIndeks];
- arr[minimumIndeks] = arr[i];
- arr[i] = temp;
- }
- }
- }
- class PasanganAB implements Comparable<PasanganAB> {
- // TODO: Lengkapi class dengan instance variable, constructor, dan method yang sesuai dan menurut Anda diperlukan
- public int a, b;
- public PasanganAB(int a, int b) {
- this.a = a;
- this.b = b;
- }
- // FIXME: Anda mungkin ingin memperbaiki cara kerja method ini
- public int hitungK() {
- int ret = 0;
- int x;
- int[] iter = new int[] {1,7,12};
- if (a == 0) {
- if(b == 0) ret = 0;
- else if(b == 1) ret = 3;
- else if(b == 2) ret = 5;
- else {x = (b-3)%3;
- ret = iter[x];}
- } else if (a == 1) {
- x = b % 3;
- ret = iter[x];
- } else if (a == 2) {
- ret = 2;
- } else if (a == 3) {
- if(b == 0) ret = 3;
- else if(b == 1) ret = 5;
- else {x = (b-2) % 3;
- ret = iter[x];}
- } else if (a == 4) {
- if(b==0) ret = 4;
- else if(b==1) ret = 16;
- else if(b==2) ret = 7;
- else if(b==3) ret = 12;
- else {x = (b-4) % 3;
- ret = iter[x];}
- } else if (a == 5) {
- if(b==0) ret = 5;
- else {x = (b-1) % 3;
- ret = iter[x];}
- } else if (a == 6) {
- if(b==0) ret = 6;
- else {ret = 11;}
- } else if (a == 7) {
- if(b==0) ret = 7;
- else if(b==1) ret = 12;
- else {x = (b-2) % 3;
- ret = iter[x];}
- } else if (a == 8) {
- if(b==0) ret = 8;
- else if(b==1) ret = 4;
- else if(b==2) ret = 16;
- else if(b==3) ret = 7;
- else if(b==4) ret = 12;
- else {x = (b-5) % 3;
- ret = iter[x];}
- } else if (a == 9) {
- if(b==0) ret = 9;
- else if(b==1) ret = 4;
- else if(b==2) ret = 16;
- else if(b==3) ret = 7;
- else if(b==4) ret = 12;
- else {x = (b-5) % 3;
- ret = iter[x];}
- } else if (a == 10) {
- if(b==0) ret = 10;
- else if(b==1) ret = 12;
- else {x = (b-2) % 3;
- ret = iter[x];}
- }
- return ret;
- }
- @Override
- public int compareTo(PasanganAB other) {
- // this = -1, other = 1
- int ret = 0;
- if(this.a - other.a > 0) ret = 1;// this a lebih besar
- else if(this.a - other.a < 0) ret = -1;// other a lebih besar
- else {
- if(this.b - other.b > 0) ret = 1;// this b lebih besar
- else if(this.b - other.b < 0) ret = -1;// other b lebih besar
- else ret = 0;
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement