백준 #30454번 얼룩말을 찾아라!

jhj·2024년 5월 22일

백준 JAVA

목록 보기
490/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int l = sc.nextInt();
		int[] count = new int[n];
		int max = -99999999;
		
		for(int i = 0; i < n; i++) {
			String a = sc.next();
			int c = 0;
			for(int j = 0; j < a.length() - 1; j++) {
				if(a.charAt(j) == '1' && a.charAt(j + 1) == '0') {
					c++;
				}
			}
			if(a.charAt(a.length() - 1) == '1') {
				c++;
			}
			count[i] = c;
			max = Math.max(max, count[i]);
		}

		int countCow = 0;
		for(int i = 0; i < n; i++) {
			if(count[i] == max) {
				countCow++;
			}
		}
		System.out.println(max + " " + countCow);
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글