-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAlpsVote.java
More file actions
72 lines (62 loc) · 2.09 KB
/
AlpsVote.java
File metadata and controls
72 lines (62 loc) · 2.09 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
package stonehee.baekjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.*;
public class AlpsVote {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
int totalVote = Integer.parseInt(br.readLine());
int staffNum = Integer.parseInt(br.readLine());
List<Staff> staffList = new ArrayList<>();
for(int i = 0; i < staffNum; i++) {
String[] input = br.readLine().split(" ");
int votes = Integer.parseInt(input[1]);
if(votes * 20 < totalVote) continue;
staffList.add(new Staff(input[0], votes));
}
sortStaffByName(staffList);
distributeChips(staffList);
printChipResult(staffList);
}
static class Staff {
String name;
int votesCast;
int chipCast;
Queue<Integer> scoreArr = new LinkedList<>();
public Staff(String name, int votes) {
this.name = name;
votesCast = votes;
setScore();
}
void setScore() {
for(int i = 1; i <= 14; i++) {
scoreArr.offer(votesCast / i);
}
}
}
static void sortStaffByName(List<Staff> staffList) {
staffList.sort(Comparator.comparing(staff -> staff.name));
}
static void distributeChips(List<Staff> staffList) {
for(int i = 1; i <= 14; i++) {
int max = 0;
int num = 0;
for (int j = 0; j < staffList.size(); j++) {
Staff staff = staffList.get(j);
int peek = staff.scoreArr.peek();
if(peek > max) {
max = peek;
num = j;
}
}
Staff staff = staffList.get(num);
staff.scoreArr.poll();
staff.chipCast++;
}
}
static void printChipResult(List<Staff> staffList) {
for (Staff staff : staffList) {
System.out.println(staff.name + " " + staff.chipCast);
}
}
}