반응형
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int n;
static int[][] votes;
static int[] votesSum;
static int rs_index;
static int loopCnt;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
votes = new int[n][3];
votesSum = new int[3];
for(int i = 0; i < votes.length; i++) {
for(int j = 0; j < 3; j++) {
votes[i][j] = sc.nextInt();
votesSum[j] += votes[i][j];
}
}
int[] sameVotesSum = makeSameVotesSumArr(votesSum);
int[] cnts = new int[3];
for(int i = 3; i > 0; i--) {
for(int j = 0; j < n; j++) {
for(int k = 0; k < 3; k++) {
if(sameVotesSum[k] == 0) continue;
if(votes[j][k] == i) cnts[k] += i;
}
}
int checkNumberCnt = 0;
int[] sameVotesSum_empty = makeSameVotesSumArr(cnts);
for(int j = 0; j < 3; j++) {
if(sameVotesSum_empty[j] != 0) checkNumberCnt++;
}
if(checkNumberCnt >= 2) {
loopCnt++;
continue;
}
break;
}
System.out.printf("%d %d\n", loopCnt < 3 ? rs_index + 1 : 0, sameVotesSum[rs_index]);
}
static int[] makeSameVotesSumArr(int[] sumArr) {
int[] maxSumArr = Arrays.copyOf(sumArr, sumArr.length);
Arrays.sort(maxSumArr);
int maxSum = maxSumArr[2];
int[] rs = new int[3];
for(int i = 0; i < 3; i++) {
if(maxSum == sumArr[i]) {
rs[i] = votesSum[i];
rs_index = i;
}
}
return rs;
}
}
반응형
'프로그래밍 > 코드업 일기' 카테고리의 다른 글
코드업(CodeUp) 2016 : 천단위 구분기호 (0) | 2023.08.11 |
---|---|
코드업(CodeUp) 4726 : 수열 (0) | 2023.08.11 |
코드업(Codeup) 3015 : 성적표 출력 (실패) (0) | 2023.08.10 |
코드업(Codeup) 4691 : 주사위 네 개 (0) | 2023.08.10 |
코드업(Codeup) 4566 : 소수 (0) | 2023.08.10 |