티스토리 뷰
Algospot에 올라온 보글 게임입니다.
보드판에서 해당하는 알파벳이 있는지 찾아주는 프로그램입니다.
https://algospot.com/judge/problem/read/BOGGLE
Python
xy = [
(-1,-1),(0,-1),(1,-1),
(-1,0), (1,0),
(-1,1), (0,1), (1,1),
]
def find_word_st(dx, dy, wd, index) :
for (x,y) in xy :
if dy+y > 4 or dy+y < 0 or dx+x > 4 or dx+x < 0 :
continue
if board[dy+y][dx+x] is wd[index] :
if length is index+1 :
return True
if find_word_st(dx+x, dy+y, wd, index+1) is True :
return True
def find_word_ch(wd) :
global length
length = len(wd)
for dy in range(0,5) :
for dx, ch in enumerate(board[dy]) :
if wd[0] is ch :
if find_word_st(dx, dy, wd, 1) is True :
return "YES"
return "NO"
if __name__ == "__main__" :
global board
for _ in range(input()) :
board = []
for _ in range(0,5) :
board.append(raw_input())
word = []
for _ in range(0,input()) :
word.append(raw_input())
for wd in word :
print "{0} {1}".format(wd, find_word_ch(wd))
입력
출력
'Python' 카테고리의 다른 글
[Python] 문자열 숫자로 변환 int(), float(), long() (0) | 2017.09.11 |
---|---|
[Python] URL Encoding & Decoding (0) | 2016.04.12 |
[Python] 16진수(Hex) < - > 문자열(String) 변환 (0) | 2016.04.11 |
[Python] 2진수, 8진수, 10진수, 16진수 변환 (0) | 2016.04.11 |
[Python] 위도, 경도 -> 기상청 X, Y 좌표 변환 (1) | 2016.02.01 |
댓글