SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
문제
N X N 크기의 단어 퍼즐을 만들려고 한다. 입력으로 단어 퍼즐의 모양이 주어진다.
주어진 퍼즐 모양에서 특정 길이 K를 갖는 단어가 들어갈 수 있는 자리의 수를 출력하는 프로그램을 작성하라.
제출 답안 & 참고 답안
T = int(input())
for test_case in range(1, T + 1):
n, k = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)] # 2차원 배열로 만들기
answer = 0
for i in range(n):
cnt = 0
for j in range(n):
if board[i][j] == 1:
cnt += 1
if board[i][j] == 0 or j==n-1:
if cnt == k:
answer += 1
cnt = 0
for j in range(n):
if board[j][i] == 1:
cnt += 1
if board[j][i] == 0 or j==n-1:
if cnt == k:
answer += 1
cnt = 0
print(f"#{test_case} {answer}")
참고 자료
https://spongebob88.tistory.com/65
[SWEA] 1979 어디에 단어가 들어갈 수 있을까 Python
[ 문제 ] 난이도: D2 문제 번호: 1979 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PuPq6AaQDFAUq&categoryId=AV5PuPq6AaQDFAUq&categoryType=CODE&problemTitle=1979&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-
spongebob88.tistory.com
'알고리즘 > Python' 카테고리의 다른 글
[Python | SWEA] 1966. 숫자를 정렬하자 (0) | 2023.05.01 |
---|---|
[Python | SWEA] 1948. 날짜 계산기 (0) | 2023.05.01 |
[Python | SWEA] 2007. 패턴 마디의 길이 (0) | 2023.04.29 |
[Python | 프로그래머스] 연속된 수의 합 (0) | 2023.04.28 |
[Python | SWEA] 1959. 두 개의 숫자열 (0) | 2023.04.28 |