2025 J3 - Product Codes
Easyimplementationsimple math
1 Solution Available
Solution 1
PYTHON1for tc in range(int(input())):
2 up, total, sign, num = "", 0, 1, ""
3 s = input()
4
5 for c in s:
6 if c.isdigit():
7 num += c
8 else:
9 if num:
10 total += sign * int(num)
11 num = ""
12 if c in "+-":
13 sign = 1 if c == "+" else -1
14 elif c.isupper():
15 up += c
16 sign = 1
17 else:
18 sign = 1
19
20 if num:
21 total += sign * int(num)
22
23 print(up + str(total))
24Test Cases
Select a test case to view input and output