데이터 엔지니어링 정복/Algorithm
[구현] 백준 - 아시아 정보올림피아드(2535)
eeaarrtthh
2022. 7. 27. 21:52
728x90
반응형
-문제
https://www.acmicpc.net/problem/2535
-자바 풀이
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
class contest {
int nation;
int stuNum;
int score;
public contest( int nation, int stuNum, int score ) {
this.nation = nation;
this.stuNum = stuNum;
this.score = score;
}
}
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt( br.readLine() );
contest[] cts = new contest[N];
StringTokenizer st;
for( int i=0; i<N; i++ ) {
st = new StringTokenizer( br.readLine() );
int tmp_nation = Integer.parseInt( st.nextToken() );
int tmp_stuNum = Integer.parseInt( st.nextToken() );
int tmp_score = Integer.parseInt( st.nextToken() );
cts[i] = new contest( tmp_nation, tmp_stuNum, tmp_score );
}
Arrays.sort( cts, new Comparator<contest>() {
@Override
public int compare( contest o1, contest o2 ) {
return o2.score-o1.score;
}
});
int[] visit = new int[N+1];
int cnt_answer = 0;
for( int i=0; i<N; i++ ) {
if( cnt_answer >= 3 ) break;
if( visit[cts[i].nation] < 2 ) {
System.out.println( cts[i].nation+" "+cts[i].stuNum );
cnt_answer++;
visit[cts[i].nation]++;
}
}
}
}
-파이썬 풀이
import sys
input = sys.stdin.readline
N = int(input())
stu = []
for _ in range(N):
stu.append( list( map(int, input().split()) ) )
stu = sorted( stu, key = lambda x: x[2], reverse=True )
cnt = [0] * (N+1)
answer = 0
i = 0
while answer < 3:
if cnt[stu[i][0]] < 2:
cnt[stu[i][0]] += 1
print( stu[i][0], stu[i][1] )
answer += 1
i += 1
728x90
반응형