■코테 기출문제/Summer,Winter Coding(~2018)
[Level 2] 영어 끝말잇기
영민 박
2020. 5. 8. 19:55
문제 : https://programmers.co.kr/learn/courses/30/lessons/12981
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
▶ 코드
# 주어진 조건대로 구현하면 되는문제
def solution(n, words):
index = -1
for i in range(len(words)):
if len(words[i]) == 1: # 한 글자인지
index = i
break
if i >= 1:
if words[i-1][-1] != words[i][0]: # 이전 단어랑 비교
index = i
break
if words[i] in words[:i]:
index = i
break
#print(index)
if index == -1:
return [0,0]
else:
#print([index%n+1, index//n+1])
return [index%n+1, index//n+1]
#solution(3, ['tank', 'kick', 'know', 'wheel', 'land', 'dream', 'mother', 'robot', 'tank'])
#solution(5, [hello, observe, effect, take, either, recognize, encourage, ensure, establish, hang, gather, refer, reference, estimate, executive])
#solution(2, ['hello', 'one', 'even', 'never', 'now', 'world', 'draw'])
#몫2, 나머지2 -> [3,3]
#몫2 나머지0 -> [1,3]