SWEA 1979. 어디에 단어가 들어갈 수 있을까?
2024. 3. 7. 21:15ㆍ코딩 테스트/SWEA
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PuPq6AaQDFAUq
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
전체 코드
# Code
def solution(mat, k):
# 가로, 세로로 순회하여 비어있는 공간을 계산하여 list에 저장한다.
# 가로 순회
space_length_list = []
for row in range(len(mat)):
space_length = 0
for col in range(len(mat[row])):
if mat[row][col] == 1:
space_length += 1
else:
if space_length > 0:
space_length_list.append(space_length)
space_length = 0
if space_length > 0:
space_length_list.append(space_length)
# 세로 순회
for col in range(len(mat[0])):
space_length = 0
for row in range(len(mat[col])):
if mat[row][col] == 1:
space_length += 1
else:
if space_length > 0:
space_length_list.append(space_length)
space_length = 0
if space_length > 0:
space_length_list.append(space_length)
result_space = [s for s in space_length_list if s == k]
return len(result_space)
# --- submit ----
T = int(input())
for test_case in range(1, T + 1):
n, k = map(int, input().split())
mat = []
for _ in range(n):
row = list(map(int, input().split()))
mat.append(row)
result = solution(mat, k)
print(f'#{test_case} {result}')
'코딩 테스트 > SWEA' 카테고리의 다른 글
SWEA 1217. 거듭제곱 (0) | 2024.03.07 |
---|---|
SWEA 2817. 부분 수열의 합 (0) | 2024.03.07 |
SWEA 2007. 패턴 마디의 길이 (0) | 2024.03.07 |
SWEA 10804. 문자열의 거울상 (0) | 2024.03.07 |
SWEA 1989. 초심자의 회문 (0) | 2024.03.07 |