Under construction

Still being built. Things may change

GCC Min Max Expression

Interview

Time limit1sMemory limit1024 MB

Summary
Evaluate an expression containing the <? (min) and >? (max) operators plus + and -, respecting precedence, left associativity, and parentheses.
Level

Medium5 of 10

Topics
Stack, Implementation, String, Math
Solved
No attempts yet

Problem

옛날 GCC에는 비표준 확장으로 각각 최솟값과 최댓값을 구해주는 이항 연산자 <?와 >?가 있었다. (현재는 지원되지 않는다.) 이 두 연산자를 포함하는 식을 계산해보자. 식을 계산할 때에는 괄호 안부터 먼저 계산하고 덧셈과 뺄셈은 <?와 >?보다 우선순위가 낮다. 우선순위가 같은 연산자(덧셈과 뺄셈, <?와 >?)끼리는 왼쪽부터 계산해야 한다. 계산 과정에서 등장하는 모든 수는 부호 있는 32비트 정수형으로 나타낼 수 있다.

Input

계산해야 할 식이 주어진다. 주어지는 식은 숫자, 괄호, 이항 연산자 +, -, <?, >?만을 포함하며(+, -는 단항 연산자로 쓰이지 않음) 띄어쓰기는 없다. 식의 길이는 100보다 작거나 같고 최소 하나의 숫자를 포함하며 문법 오류가 있는 식은 주어지지 않는다.

Output

계산 결과를 출력한다.

Examples4

  1. Example 1

    Input
    35<?40
    Expected output
    35
    
  2. Example 2

    Input
    7>?(30<?(50+2-6)>?18)>?3+4<?1>?49
    Expected output
    79
    
  3. Example 3

    Input
    1<?2
    
    Expected output
    1
    
  4. Example 4

    Input
    10+20
    
    Expected output
    30