반응형
Notice
Recent Posts
Recent Comments
Link
지구정복
[구현] 백준 - 아시아 정보올림피아드(2535) 본문
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
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[재귀] 백준 - 부등호(2529) (0) | 2022.08.08 |
---|---|
[구현] 프로그래머스 - 폰켓몬(1845) 자바 (0) | 2022.08.05 |
[DP] 백준 - 이친수 (2193) (0) | 2022.07.24 |
[구현/정렬] 프로그래머스 - 실패율 (Java) (0) | 2022.07.21 |
[그리디] 프로그래머스 - 체육복 (java & python) (0) | 2022.07.21 |
Comments