https://www.acmicpc.net/problem/2535
2535번: 아시아 정보올림피아드
첫 번째 줄에는 대회참가 학생 수를 나타내는 N이 주어진다. 단, 3 ≤ N ≤ 100이다. 두 번째 줄부터 N개의 줄에는 각 줄마다 한 학생의 소속 국가 번호, 학생 번호, 그리고 성적이 하나의 빈칸을 사
www.acmicpc.net
알고리즘 분류
- 구현
- 정렬
풀이
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st;
int country, student, score;
Node node;
Node []nodes = new Node[n];
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
country = Integer.parseInt(st.nextToken());
student = Integer.parseInt(st.nextToken());
score = Integer.parseInt(st.nextToken());
node = new Node(country, student, score);
nodes[i] = node;
} // for
Arrays.sort(nodes, (o1, o2) -> o2.score - o1.score );
int cnt = 0;
StringBuilder sb = new StringBuilder();
int []count = new int[n+1];
for (int i = 0; i < n; i++) {
if(count[nodes[i].country] == 2){
continue;
}else if(cnt == 3){
break;
}
sb.append(nodes[i].country).append(" ").append(nodes[i].student).append("\n");
count[nodes[i].country]++;
cnt++;
} // for
System.out.println( sb.substring(0, sb.length() -1).toString() );
}
public static class Node{
int country;
int student;
int score;
public Node(int country, int student, int score) {
this.country = country;
this.student = student;
this.score = score;
}
}
}
'BOJ, Programmers' 카테고리의 다른 글
[Java] 백준 1015 (수열 정렬) 자바 문제 풀이 (0) | 2024.09.28 |
---|---|
[Java] 백준 14501 (퇴사) 자바 문제풀이 (0) | 2024.04.25 |
[Java] 백준 1527 (금민수의 개수) 자바 문제 풀이 (0) | 2024.04.15 |
[Java] 백준 2075 (N번째 큰 수) 자바 문제 풀이 (1) | 2024.04.15 |
[Java] 백준 1312 번 (소수) 문제 풀이 (0) | 2024.04.10 |