[백준 5355 파이썬] 화성 수학

일단 해볼게·2022년 10월 9일
0

백준

목록 보기
21/132

https://www.acmicpc.net/problem/5355

# 화성 수학

import sys
input = sys.stdin.readline

T = int(input().rstrip())
result = 0

for _ in range(T):
    op = input().rstrip().split() # 한 줄을 리스트로 받아옴
    for i in op:
        if i == '@':
            result *= 3
        elif i == '%':
            result += 5
        elif i == '#':
            result -= 7
        else: # 숫자일 때 
            result = float(i)
    print("{:.2f}".format(result))
    result = 0 # 출력이 끝난 결과 초기화
  • import sys
    input = sys.stdin.readline 을 이용해 한 줄을 리스트로 받아온다.
  • "{:.2f}".format(result) 말고도 print(round(result, 3)) 같은 방법으로 소수점 자리수 제한을 둘 수 있다.

참고
https://blockdmask.tistory.com/534

profile
시도하고 More Do하는 백엔드 개발자입니다.

0개의 댓글