알고리즘 공부/백준

(Python)백준 코딩테스트 연습 - 크로스워드(1706)

HRuler 2023. 4. 30. 19:24

1. 문제

https://www.acmicpc.net/problem/1706

 

1706번: 크로스워드

동혁이는 크로스워드 퍼즐을 좋아한다. R×C 크기의 크로스워드 퍼즐을 생각해 보자. 이 퍼즐은 R×C 크기의 표로 이루어지는데, 퍼즐을 다 풀면 금지된 칸을 제외하고는 각 칸에 알파벳이 하나씩

www.acmicpc.net

2. 풀이

import sys
# input = sys.stdin.readline

# r, c : 크로스 워드 크기
r, c = map(int, input().split())

# rList : 가로 문자열 리스트
rList = []
# cList : 세로 문자열 리스트
cList = ["" for i in range(c)]

for i in range(r):
    word = input().strip()
    rList.append(word)
    for k, v in enumerate(word):
        cList[k] += v

strTotal = []
for i in rList:
    splitList = i.split("#")
    for j in splitList:
        if len(j) >= 2:
            strTotal.append(j)
for i in cList:
    splitList = i.split("#")
    for j in splitList:
        if len(j) >= 2:
            strTotal.append(j)

strTotal.sort()
# print(strTotal)
print(strTotal[0])