말랑한 하루

[SW Expert Academy] 1979 어디에 단어가 들어갈 수 있을까 [Java] 본문

문제풀이/SWexpert Academy

[SW Expert Academy] 1979 어디에 단어가 들어갈 수 있을까 [Java]

지수는말랑이 2021. 1. 21. 21:49
반응형

[ 핵심풀이 ]

[ 핵심소스 ]

[ Java ]

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        for(int t=1;t<=tc;t++) {
            int N=sc.nextInt();
            int len=sc.nextInt();
			
            int puzzle[][] = new int [N][N];
            int Size[] = new int[N+1];
			
            for(int y=0;y<N;y++)
                for(int x=0;x<N;x++)
                    puzzle[y][x] = sc.nextInt();
			
            for(int y=0;y<N;y++) {
                int cnt=0;
                for(int x=0;x<N;x++) {
                    if (puzzle[y][x] == 0) {
                        Size[cnt]++;
                        cnt=0;
                    }
                    else
                        cnt++;
                }
                Size[cnt]++;
            }
            for(int x=0;x<N;x++) {
                int cnt=0;
                for(int y=0;y<N;y++) {
                    if (puzzle[y][x] == 0) {
                        Size[cnt]++;
                        cnt=0;
                    }
                    else
                        cnt++;
                }
                Size[cnt]++;
            }
            System.out.println("#"+t+" "+Size[len]);
        }
        sc.close();
    }
}
반응형
Comments