[D2] 어디에 단어가 들어갈 수 있을까 - 1979
성능 요약
메모리: 21,312 KB, 시간: 157 ms, 코드길이: 1,812 Bytes
제출 일자
2023-10-17 17:32
출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.*;
import java.io.*;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int map[][];
for(int tc = 1; tc <= T; tc++)
{
int N = sc.nextInt();
int K = sc.nextInt();
map = new int[N][N];
int result = 0;
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
map[i][j] = sc.nextInt();
}
}
// 가로
for(int i = 0; i < N; i++){
int count = 0;
for(int j = 0; j < N; j++){
// 흰색일 때
if(map[i][j] == 1){
count++;
}
//검정색일 때
else{
if(count == K){
result++;
}
count = 0;
}
}
if(count == K){
result++;
}
}
// 세로일 때
for(int i = 0; i < N ; i++){
int count = 0;
for(int j = 0; j < N; j++){
// 흰색일 때
if(map[j][i] == 1){
count++;
}
// 검정색일 때
else{
if( count == K){
result++;
}
count = 0;
}
}
if(count == K){
result++;
}
}
System.out.printf("#%d %d\n",tc,result);
}
}
}
'알고리즘 - SWEA > D2' 카테고리의 다른 글
[SW expert Academy] SWEA 1974번 스도쿠 검증 자바(Java) (0) | 2023.10.17 |
---|---|
[SW expert Academy] SWEA 1976번 시각 덧셈 자바(Java) (0) | 2023.10.17 |
[SW expert Academy] SWEA 1983번 조교의 성적 매기기 자바(Java) (1) | 2023.10.16 |
[SW expert Academy] SWEA 1984번 중간 평균값 구하기 자바(Java) (1) | 2023.10.16 |
[SW expert Academy] SWEA 1986번 지그재그 숫자 자바(Java) (0) | 2023.10.16 |