-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q7568.java
60 lines (52 loc) · 1.57 KB
/
Q7568.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Date: 2018. 10. 12.
* Author: inhyuck | https://github.com/inhyuck
* Solution URL: https://github.com/inhyuck/algorithm
* Title: 덩치
* description: 덩치 순위 매기기 - 문제링크 참조
* Problem URL: https://www.acmicpc.net/problem/7568
*/
package io.inhyuck.brute_force;
import java.util.Arrays;
import java.util.Scanner;
public class Q7568 {
static int n;
static Person[] people;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
people = new Person[n];
for (int i = 0; i < n; i++) {
people[i] = new Person(scanner.nextInt(), scanner.nextInt());
}
Arrays.stream(people).forEach(person -> {
System.out.print(computeRank(person) + " ");
});
}
private static int computeRank(Person person) {
int count = 0; //덩치가 더 큰 사람들 count
for (int i = 0; i < n; i++) {
if (Person.compare(people[i], person) > 0) {
count++;
}
}
return count + 1;
}
static class Person {
int weight;
int height;
public Person(int weight, int height) {
this.weight = weight;
this.height = height;
}
static int compare(Person p1, Person p2) {
if (p1.weight > p2.weight && p1.height > p2.height) {
return 1;
}
if (p1.weight < p2.weight && p1.height < p2.height) {
return -1;
}
return 0;
}
}
}