programmers - 카펫(파이썬)
resilient
·2021. 5. 14. 02:32
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/42842
코딩테스트 연습 - 카펫
Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과
programmers.co.kr
def solution(brown, yellow):
answer = []
total = brown+yellow
totallist = []
for i in range(1,total+1):
if total % i == 0:
totallist.append(i)
for i in totallist:
for j in totallist:
if (i-2)*(j-2) == yellow: #이게 핵심이다
a = i
b = j
if totallist[len(totallist)//2]**2==total: # 정사각형 모양의 카펫일때
answer.append(totallist[len(totallist)//2])
answer.append(totallist[len(totallist)//2])
else:
answer.append(a)
answer.append(b)
return answer
if __name__ == "__main__":
#인터프리터에서 직접실행했을때만 코드를 실행해라
brown = 24
yellow = 24
print(solution(brown,yellow))
반응형
'자료구조 & 알고리즘 > 프로그래머스(programmers)' 카테고리의 다른 글
programmers - 더 맵게 (0) | 2021.06.01 |
---|---|
programmers - 셔틀버스 (0) | 2021.05.29 |
programmers - 네트워크(파이썬) (0) | 2021.05.13 |
programmers - 기지국 설치(파이썬) (0) | 2021.05.12 |
programmers - 합승 택시요금 (0) | 2021.05.08 |