Skip to content

Instantly share code, notes, and snippets.

@nattybear
Created June 3, 2017 13:31
Show Gist options
  • Save nattybear/1993cc653862deed3a10b10835853efa to your computer and use it in GitHub Desktop.
Save nattybear/1993cc653862deed3a10b10835853efa to your computer and use it in GitHub Desktop.
알고스팟 왕초보 구현 문제
# 문자열로 된 ('x', 'y') 좌표를 받아서
# 내장함수 map을 이용하여 숫자 좌표를 리턴한다.
def parse(x):
x = x.split()
return map(int, x)
def func():
# 사용자 입력을 세번 받는다.
pos1 = input()
pos2 = input()
pos3 = input()
# 위에서 정의한 사용자 함수 parse를 이용해서
# 각 좌표 변수에 숫자로 저장한다.
x1, y1 = parse(pos1)
x2, y2 = parse(pos2)
x3, y3 = parse(pos3)
x4, y4 = 0, 0
# 어느 두 좌표의 x값이 같다면
# 나머지 두 좌표의 x값은 같을 것이다.
# 따라서 경우의 수를 검사해서
# 마지막 4번째 좌표를 구한다.
if x1 == x2:
x4 = x3
elif x1 == x3:
x4 = x2
else:
x4 = x1
if y1 == y2:
y4 = y3
elif y1 == y3:
y4 = y2
else:
y4 = y1
# 결과를 화면에 출력한다.
print(x4, y4)
# 몇 번 실행할지 입력을 받는다.
count = int(input())
# 위에서 구현한 코드를 입력 받은
# 횟수만큼 실행한다.
for i in range(count): func()
@nattybear
Copy link
Author

다시 한 번 말하지만 "주석"을 적는 것은 매우 중요

  • 주석은 자기 자신과 다른 사람을 위해서 반드시 적어야 해!

내장 함수와 사용자 정의 함수를 적절히 이용

  • parse 사용자 정의 함수를 이용하면 코드를 재사용 하기 좋다!
  • map 내장 함수를 이용하면 코드를 더 간결하게 작성 할 수 있어!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment