작성
·
263
0
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner kb=new Scanner(System.in);
int student,pos,len=kb.nextInt(), table[][] = new int[len][len],max=Integer.MIN_VALUE,currMax,answer=0;
//입력받기
for(int i=0;i<len;i++)for(int j=0;j<len;j++)table[i][j]=kb.nextInt();
//찾기
for(int stdnum=0;stdnum<len;stdnum++){
//check배열을 만들어, 같은반이었던 학생은 true로 변경
boolean check[] = new boolean[len];
for(int grade=0;grade<len;grade++){
student=table[stdnum][grade];
pos=0;
while(pos<len){
if(table[pos][grade]==student)check[pos]=true;
pos++;
}
}
//같은반이었던 학생 수 만큼 currMax에 더하며 카운트..
currMax=0;
for(int i=0;i<len;i++)if(check[i])currMax++;
//currMax가 기존Max보다 크면 answer(반장번호)변경;
if(currMax>max){
max=currMax;
answer=stdnum+1;
}
}
System.out.println(answer);
};
};