728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com

import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
int n = sc.nextInt();
int m = sc.nextInt();
// int arr[][] = new int[n + 1][m + 1];
int count[] = new int[n+1];
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= m; j++) {
// arr[i][j] = sc.nextInt();
// }
// }
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int num = sc.nextInt();
if(num==1) {
count[i]++;
}
}
}
int max=Integer.MIN_VALUE;
int maxCount=0;
for (int i = 1; i < count.length; i++) {
max=Math.max(max, count[i]);
}
for(int i=1;i<count.length;i++) {
if(max==count[i]) {
maxCount++;
}
}
System.out.println("#"+tc+" "+maxCount+" "+max);
}
}
}
배열을 관리해뒀다가 따로 쓸 일이 없으면 값이 1인지 아닌지를
반복문 하나에서 바로 체크해줘도 된다.
728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 보충학습과 평균 (D3) (0) | 2024.08.31 |
|---|---|
| [SW Expert Academy] 원 안의 점 (D3) (0) | 2024.08.31 |
| [SW Expert Academy] 준홍이의 카드놀이 (D3) (0) | 2024.08.31 |
| [SW Expert Academy] 코딩 토너먼트1 (D3) (0) | 2024.08.31 |
| [SW Expert Academy] [S/W 문제해결 기본] 3일차 - 회문1 (0) | 2024.08.29 |