반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 파이썬
- 코엑스
- 영어
- hadoop
- BFS
- 알고리즘
- 개발
- 양평
- dfs
- Data Engineer
- 용인맛집
- 코딩
- 자바
- 프로그래머스
- bigdata engineer
- java
- 코딩테스트
- 코테
- Trino
- 코엑스맛집
- 백준
- BigData
- 맛집
- apache iceberg
- bigdata engineering
- Data Engineering
- 여행
- HIVE
- Iceberg
- 삼성역맛집
Archives
- Today
- Total
지구정복
[구현] 백준 - 아시아 정보올림피아드(2535) 본문
728x90
반응형
-문제
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.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 |