#include #include #include #include #include #define MAX_S_LEN 100 uint8_t shunting_yard_input_priority(char c) { if (isdigit(c)) return 5; switch (c) { case '(': return 4; case '+': case '-': return 2; case ')': return 1; case '\0': return 0; } } uint8_t shunting_yard_stack_priority(char c) { if (isdigit(c)) return 5; switch (c) { case '+': case '-': return 3; case '(': return 1; case '\0': return 0; } } void shunting_yard_operate(int64_t *l, char op, int64_t r) { switch (op) { case '+': *l += r; break; case '-': *l -= r; break; } } int64_t shunting_yard(const char input[], size_t input_len) { size_t input_pos = 0; int64_t output_stack[MAX_S_LEN]; size_t output_stack_pos = 0; char stack[MAX_S_LEN]; stack[0] = '\0'; size_t stack_pos = 1; while (input_pos < input_len || stack_pos > 0) { uint8_t input_priority = shunting_yard_input_priority(input[input_pos]); uint8_t stack_priority = shunting_yard_stack_priority(stack[stack_pos - 1]); if (input_priority > stack_priority) { stack[stack_pos++] = input[input_pos++]; } else if (input_priority < stack_priority) { char c = stack[--stack_pos]; if (isdigit(c)) { output_stack[output_stack_pos++] = c - '0'; } else { int64_t r = output_stack[--output_stack_pos]; shunting_yard_operate(&output_stack[output_stack_pos - 1], c, r); } } else { --stack_pos; input_pos++; } } return output_stack[0]; } int main(void) { char s[MAX_S_LEN]; scanf("%s", s); int64_t ans = shunting_yard(s, strlen(s) + 1); printf("%" PRId64 "\n", ans); }