본문 바로가기

개발

날개를 달고 자바

https://www.acmicpc.net/problem/1236

 

1236번: 성 지키기

첫째 줄에 성의 세로 크기 N과 가로 크기 M이 주어진다. N과 M은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 성의 상태가 주어진다. 성의 상태는 .은 빈칸, X는 경비원이 있는 칸이다

www.acmicpc.net

 


이제 업무도 파이썬에서 자바로 바꼈겠다...

자바의정석 책 뒷부분을 읽고있는데 은근 재밌다.

스트림이라든가 람다라든가 이러한 부분이 파이썬과 많이 비슷하다는 생각이 들어 자바도 금방 익숙해 질 수 있겠다 느꼈다.

하다보면 언젠가 파이썬처럼 자유롭게 개발하고 있는 날 발견할 수 있겠지..

이제 올해도 다 끝났고 조만간 회고록이나 써봐야겠다.

 

package com.job;

import java.util.*;

public  class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        char[][] map = new char[N][M];
        for (int i = 0; i < N; i++)
            map[i] = sc.next().toCharArray();

        Boolean[] rowExist = new Boolean[N];
        Boolean[] colExist = new Boolean[M];
        Arrays.fill(rowExist, false);
        Arrays.fill(colExist, false);

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if (map[i][j] == 'X'){
                    rowExist[i] = true;
                    colExist[j] = true;
                }
            }
        }
        long rowExistCount = Arrays.stream(rowExist).filter(x->!x).count();
        long colExistCount = Arrays.stream(colExist).filter(x->!x).count();
        System.out.println(Math.max(rowExistCount, colExistCount));
    }
}