hahn

[백준 - JAVA] 임시 반장 정하기 본문

코딩테스트 연습/백준(JAVA)

[백준 - JAVA] 임시 반장 정하기

hahn 2021. 9. 15. 16:10
728x90
반응형

1268번: 임시 반장 정하기 (acmicpc.net)

 

1268번: 임시 반장 정하기

첫째 줄에는 반의 학생 수를 나타내는 정수가 주어진다. 학생 수는 3 이상 1000 이하이다. 둘째 줄부터는 1번 학생부터 차례대로 각 줄마다 1학년부터 5학년까지 몇 반에 속했었는지를 나타내는 5

www.acmicpc.net

http://boj.kr/bc5ba871c1c048709cb243af53bfcd19

 

공유 소스 보기

 

www.acmicpc.net

더보기
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
		
		int studentCount = sc.nextInt(),
			store = 0, result = 0;
		
		int[][] studentInfo = new int[studentCount][5];
		
		for(int i = 0; i < studentCount; i++) {
			
			for(int j = 0; j < 5; j++) {
				
				studentInfo[i][j] = sc.nextInt();
				
			}
			
		}
		
		for(int i = 0; i < studentInfo.length; i++) {
			
			studentCount = 0;
			
			for(int l = 0; l < studentInfo.length; l++) {
				
				for(int j = 0; j < studentInfo[0].length; j++) {
					
					if(i == l) continue;
					
					if(studentInfo[i][j] == studentInfo[l][j]) {
						studentCount++;
						break;
					}
					
				}
				
			}
			
			if(studentCount > store) {
				
				result = i;
				store = studentCount;
				
			}
				
		}
		
		System.out.println(result + 1);
        
    }
    
}

문제 이해를 잘 못해서 틀렸다.

 

계속하니까 당 떨어져서 문제도 못 읽네;;

 

for문 순서 바꿔주고 continue break 조건 추가해서 완료했다.

728x90
반응형

'코딩테스트 연습 > 백준(JAVA)' 카테고리의 다른 글

[백준 - JAVA] 집 주소  (0) 2021.09.15
[백준 - JAVA] 엄청난 부자2  (0) 2021.09.15
[백준 - JAVA] 핸드폰 요금  (0) 2021.09.15
[백준 - JAVA] 모음의 개수  (0) 2021.09.15
[백준 - JAVA] 이진수 덧셈  (0) 2021.09.15