문제 : https://www.acmicpc.net/problem/12760

 

12760번: 최후의 승자는 누구?

입력의 첫 줄에 플레이어의 수 \(N\)과 가진 카드 수 \(M\)이 입력 된다. \(( 2 \le N \le100, 1 \le M \le 100 )\) 그 다음 \(N\)줄에 걸쳐 각 플레이어가 들고 있는 카드에 적힌 숫자들이 입력된다. \(( 1 \le\) 카

www.acmicpc.net

문제 요약 : 가장 많은 점수 획득한 플레이어 번호 출력

입력 출력
2 ≤ N(플레이어 수) ≤ 100
1 ≤ M(카드 수) ≤ 100
1 ≤ 카드에 적힌 숫자 ≤ 100

가장 많은 점수를 획득한 플레이어 번호 출력
승자가 다수일 때 오름차순으로 출력

JAVA

소스코드 : https://github.com/cbkpar/BOJ/blob/main/boj_12760.java

채점 번호 아이디 문제 번호 결과 메모리 시간 언어 코드 길이
30892868 cbkpar 12760 맞았습니다!! 15480KB 180ms Java 11 1065B
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n,m,i,j,mxcnt;
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		int[][] arr = new int[n][m];
		int[] mx = new int[m];
		int[] cnt = new int[n];
		for(i=0;i<n;i++) {
			st = new StringTokenizer(br.readLine());
			for(j=0;j<m;j++) arr[i][j] = Integer.parseInt(st.nextToken());
		}
		for(i=0;i<n;i++) Arrays.sort(arr[i]);
		for(i=0;i<n;i++) for(j=0;j<m;j++) mx[j] = Math.max(mx[j], arr[i][j]);
		for(i=0;i<n;i++) for(j=0;j<m;j++) if(mx[j]==arr[i][j]) cnt[i]++;
		mxcnt = 0;
		for(i=0;i<n;i++) mxcnt = Math.max(mxcnt, cnt[i]); 
		for(i=0;i<n;i++) if(mxcnt==cnt[i]) sb.append((i+1)+" ");
		System.out.println(sb);
	}
}

각 플레이어의 카드를 오름차순 혹은 내림차순으로 정렬한 후

각 회차에서 가장 높은 숫자 카드를 내는 플레이어의 숫자를 세고

가장 높은 숫자를 많이 내는 플레이어 번호를 출력한다.

 

예제 ) 

5 3

5 4 3

3 4 5

3 5 4

4 5 3

3 4 4

+ Recent posts