[백준/파이썬] 11784번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 11784번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
In the movie The Martian (2015), astronaut Mark Watney, one of the crew members of Mission Ares III, was left behind on Mars due to an unexpected incident during the surface exploration on the planet Mars. The communication with Earth was quasi-inexistent. Fortunately, Mark Watney managed to establish a very simple way to communicate with NASA at the mission control base on Earth through hexadecimal codes.
Mark could receive one simple code at a time which he could detect as a hexadecimal digit or hex code including 0-9 and A-F. …
입력 요약
The input contains several lines of hex codes only (0-9, A-F). Each line contains an even number of hex digits that you have to transform into a plain text message. One pair of hex digits corresponds to a single character. There are less than 250 hex digits in each line. …
출력 요약
For each line of hex codes, print out the corresponding text message.
코드
import sys
for line in sys.stdin:
res = ""
for i in range(0, len(line)-1, 2):
s = line[i:i+2]
res += chr(int(s, 16))
print(res)
설명
핵심은 구현 관점에서 In the movie The Martian (2015), astronaut Mark Watney, one of the crew members of Mission Ares III, was left behind on Mars due to an unexpected inci …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기