풀이)
모든 행과 열에 한 명 이상의 경비원이 있게끔 배치하려 할 때, 필요한 최소의 경비원 수는?
입력받은 배열에 대해, 경비원이 없는 세로줄 수와 경비원이 없는 가로줄 수 중 큰 값을 구하면 된다.
내 코드)
import java.io.*;
import java.util.*;
public class Backjoon1236 {
public static void main(String[]args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int nCount = M; //경비원이 없는 세로줄
int mCount = N; //경비원이 없는 가로줄
String input[] = new String[N];
for(int i=0;i<N;i++) {
String str = bf.readLine();
input[i] = str;
if(str.contains("X")) {
mCount--;
}
}
char[][] arr = new char[N][M];
for(int i=0;i<N;i++) {
arr[i] = input[i].toCharArray();
}
for(int i=0;i<M;i++) {
for(int j=0;j<N;j++) {
if(arr[j][i] == 'X') {
nCount--;
break;
}
}
}
int ans = nCount>mCount?nCount:mCount;
System.out.println(ans);
}
}