#CCBCHHAI0000032. Menu phi tương tác (Non-interactive Menu)
Menu phi tương tác (Non-interactive Menu)
Non-interactive Menu
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
A calculator receives a stream of command pairs (m, x). Initially total = 0. Command m = 1 adds x; command m = 2 subtracts x. Upon m = 0, stop and print only the final total. The terminating command is the pair 0 0 and has no effect on the total. Do not print any prompts or menu text.
Input
A sequence of integer pairs m x, separated by whitespace, where m belongs to {0,1,2}. The last pair is 0 0; previous commands have code 1 or 2. Operands may be negative, zero or positive.
Output
Print one integer: the final total, followed by a newline.
Subtasks
- Subtask 1 (20%): At most 5 pairs including
0 0; . - Subtask 2 (30%): At most 100 pairs including
0 0; . - Subtask 3 (50%): At most 10000 pairs including
0 0; .
Examples
Example 1
Input
1 8
2 3
1 -4
0 0
Output
1
Explanation
Starting from 0: add 8 → 8, subtract 3 → 5, add -4 → 1; 0 0 stops processing.
Example 2
Input
0 0
Output
0
Explanation
The first command terminates the stream, so the unchanged total is zero.