[백준/파이썬] 13228번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 13228번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
If you remember the preliminary round, we already measured distances in Manhattan. Besides being a grid, Manhattan also has very tall buildings scattered all over the island.
Suppose I want to go to from my apartment that is at position x=3, y=4, floor=3 to my friends apartment, which is x=3, y=5, floor=2. …
입력 요약
The first line will contain the number of test cases T. Each of the next T lines will contain 2 points. You have to compute the distance between these two points. Each test cases is a line with 6 integer numbers x1, y1, floor1, x2, y2, floor2. See the examples below. …
출력 요약
For each test case a single line with the distance between the two points.
코드
import sys;read=sys.stdin.readline
for T in range(int(read())):
a,b,c,d,e,f=map(int,read().split())
print(abs(a-d)+abs(b-e)+c+f)
설명
핵심은 구현 관점에서 If you remember the preliminary round, we already measured distances in Manhattan. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기