on
백준 2535 - 아시아 정보올림피아드
백준 2535 - 아시아 정보올림피아드
https://www.acmicpc.net/problem/2535
★ 풀이
"1등과 2등의 나라가 같으면 3등은 1등의 나라와 다른 나라여야 한다."
== "1등과 2등의 나라가 다르면 3등의 나라는 뭐가 나와도 상관이 없다."
이것만 유의하고 문제를 풀면 된다.
먼저 점수기준으로 해서 내림차순 정렬을 해준다. 그리고 나서 위의 조건을 아래와 같이 적용해주면
if(p[0].country == p[1].country) { bw.write(p[0].country +" "+p[0].id+"
"); bw.write(p[1].country +" "+p[1].id+"
"); for(int i = 2; i
"); break; } } }else { for(int i = 0; i<3; i++) { bw.write(p[i].country+" "+p[i].id+"
"); } }
쉽게 풀 수 있다.
★ 소스 코드
import java.io.*; import java.util.*; // 좋은 코드 흡수하기! public class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException { // 3명을 출력(금은동) int n = Integer.parseInt(br.readLine()); Player p[] = new Player[n]; for(int i = 0; i
"); bw.write(p[1].country +" "+p[1].id+"
"); for(int i = 2; i
"); break; } } }else { for(int i = 0; i<3; i++) { bw.write(p[i].country+" "+p[i].id+"
"); } } bw.flush(); } } class Player implements Comparable{ int country; int id; int score; Player(int country, int id, int score){ this.country = country; this.id = id; this.score = score; } public int compareTo(Player o) { return o.score - this.score; // 점수 기준 내림차순 } }
from http://sweet-smell.tistory.com/116 by ccl(A) rewrite - 2021-11-27 14:28:20