SWEA 1979

녹색자몽·2021년 8월 10일
0

Algorithm

목록 보기
31/80
post-thumbnail

어디에 단어가 들어갈 수 있을까

행과 열을 나누어 문제를 풀어보았다

T = int(input())
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
for test_case in range(1, T + 1):
    size, w_len = map(int, input().split())
 
    mat = []
    
    for i in range(size):
        rows = list(input().split())
        mat.append(rows)
     
    test_ex= ''.join(['1']*w_len)
     
 
    cnt = 0
     
    #행
    for row in mat:
        check=''.join(row).split('0')
        if test_ex in check:
            cnt += check.count(test_ex)
 
    #열
    for x in range(size):
        check=[]
        for y in range(size):
            check.append(mat[y][x])
        check = ''.join(check).split('0')
        if  test_ex in check:
            cnt += check.count(test_ex)
     
    print('#{} {}'.format(test_case, cnt))
profile
볕 좋은 날 시작하는 개발일기

0개의 댓글

Powered by GraphCDN, the GraphQL CDN