Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
sabira-khan committed Apr 28, 2022
1 parent b036b43 commit 10ddbf8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
2 changes: 0 additions & 2 deletions JavaSolutions/src/com/gitproject/Beecrowd1258_uri.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.gitproject;

//this was a good exercise, learnt a lot.

import java.util.Arrays;
import java.util.Scanner;

Expand Down
69 changes: 69 additions & 0 deletions JavaSolutions/src/com/gitproject/Beecrowd1766_uri.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.gitproject;


import java.util.Arrays;
import java.util.Scanner;

class Deer implements Comparable<Deer> {
public String name;
public int weight;
public int age;
public double height;

public Deer(String name, int weight, int age, double height) {
this.name = name;
this.weight = weight;
this.age = age;
this.height = height;
}

@Override
public int compareTo(Deer o) {

if (o.weight == weight) {
if (o.age == age) {
if (o.height == height) {
return name.compareTo(o.name);
} else {
return height > o.height ? 1 : -1; //ascending
}
} else {
return age > o.age ? 1 : -1; //ascending
}
} else {
return weight < o.weight ? 1 : -1; //descending
}
}
}


public class Beecrowd1766_uri {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();

int c = 1;

while (t-- > 0) {

int n = s.nextInt();
int m = s.nextInt();
s.nextLine();

Deer[] deers = new Deer[n];
for (int i = 0; i < n; i++) {
String[] temp = s.nextLine().split(" ");
deers[i] = new Deer(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), Double.parseDouble(temp[3]));
}

Arrays.parallelSort(deers);
System.out.printf("CENARIO {%d}\n", c);
c++;

for (int i = 0; i < m; i++) {
System.out.println(i+1 + " - " + deers[i].name);
}
}
}
}

0 comments on commit 10ddbf8

Please sign in to comment.