Created
October 20, 2019 06:13
-
-
Save velasquezkevin/eb0e1b41aefa7985096959665faf22a0 to your computer and use it in GitHub Desktop.
Problem B. Bracket Sequence - ICPC 19/10/2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = int(input()) | |
| x = input().split(" ") | |
| i = total = 0 | |
| def operar(op = True, subtotal = 1): | |
| global i, x | |
| while True: | |
| el = x[i] | |
| i += 1 | |
| if el == ")": | |
| return subtotal | |
| elif el == "(": | |
| if op: subtotal *= operar(not op, 1 if not op else 0) | |
| else: subtotal += operar(not op, 1 if not op else 0) | |
| else: | |
| val = int(el) | |
| if op: subtotal *= val | |
| else: subtotal += val | |
| def main(): | |
| global i, n, total, x | |
| while i < n: | |
| if x[i] == "(": | |
| i += 1 | |
| total += operar() | |
| elif x[i] == ")": | |
| print("\nclosure\n") | |
| else: | |
| total += int(x[i]) | |
| i += 1 | |
| print(total) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment