본문 바로가기
Algorithm/swea

[파이썬]swea 1979: 어디에 단어가 들어갈 수 있을까

by 갈잃자 2023. 2. 3.

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PuPq6AaQDFAUq&categoryId=AV5PuPq6AaQDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com


단순 구현문제

t = int(input())
for tc in range(1,t+1):
    n,k = list(map(int,input().split()))
    arr = [list(map(int,input().split()))for _ in range(n)]
    answer = 0

    # 가로로 탐색
    for y in range(n):
        cnt = 0
        for x in range(n):
            if arr[y][x] ==0:
                if cnt ==k:
                    answer +=1
                cnt =0
                continue
            else:
                cnt +=1
        if cnt ==k:
            answer +=1

    #세로로 탐색
    for x in range(n):
        cnt = 0
        for y in range(n):
            if arr[y][x] ==0:
                if cnt ==k:
                    answer +=1
                cnt = 0
                continue
            else:
                cnt +=1
        if cnt ==k:
            answer +=1
    print(f"#{tc} {answer}")

댓글