본문 바로가기

코딩 테스트/백준

[Python] 백준 5355 화성 수학

 

문제 분석

  • 화성에서의 연산자는 지구와 다르다
  • @ : x3
  • % : +5
  • # : -7
  • 주어지는 수는 정수거나 소수 첫째까지의 실수

 

정답 코드

import sys
input = sys.stdin.readline

tc = int(input())

for _ in range(tc) :
    mars = list(input().split())
    num = float(mars[0])
    oper = mars[1:]

    for op in oper :
        if op == '@' :
            num *= 3
        elif op == '%' :
            num += 5
        elif op == '#' :
            num -= 7
    print("{:.2f}".format(num))