222. 전국 대회 선발 고사

김해준's avatar
Jan 09, 2026
222. 전국 대회 선발 고사

사용언어 : Java

문제
notion image
notion image
풀이
/* attendance의 원소 중 적어도 3개는 true입니다. -> 무조건 3명은 존재함 rank를 반복하면서 등수가 작은 수 부터 찾아내고 찾은 등수가 attendance에서 false라면 다음 등수를 찾아내면 될거같음 123등 전부 채울 때 까지 반복 1~3등까지 구해진다면 주어진 식대로 계산 해서 반환 */ class Solution { public int solution(int[] rank, boolean[] attendance) { int[] ranks = new int[3]; int index = 0; int afterRank = -1; int curRank = -1; for(int i = 0; i < 3; i++) { for(int j = 0 ; j < rank.length; j++) { if(attendance[j]) { if(afterRank < 0) { if(curRank <= 0) { curRank = rank[j]; ranks[index] = j; } else if(rank[j] < curRank) { curRank = rank[j]; ranks[index] = j; } } else { if(rank[j] <= afterRank) continue; if(curRank <= 0) { curRank = rank[j]; ranks[index] = j; } else if(rank[j] < curRank) { curRank = rank[j]; ranks[index] = j; } } } } afterRank = curRank; curRank = -1; index++; } int answer = (10000 * ranks[0]) + (100 * ranks[1]) + ranks[2]; return answer; } }
notion image
Share article