#CCBCHMOT0000017. Tổng dãy kết thúc bởi số 0 (Sum Until Zero)
Tổng dãy kết thúc bởi số 0 (Sum Until Zero)
Sum Until Zero
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Read a sequence of integers ending at its first zero. Sum all preceding, nonzero values, which can be positive or negative. Do not include the terminating zero. If zero comes first, the sum is zero.
Input
Integers separated by whitespace; the first zero terminates the sequence.
Output
Print one integer: the sum before the first zero.
Subtasks
- Subtask 1 (20%): At most 5 preceding values, abs(ai) <= 10.
- Subtask 2 (30%): At most 200 preceding values, abs(ai) <= 10^4.
- Subtask 3 (50%): At most 10^5 preceding values, abs(ai) <= 10^6.
Examples
Example 1
Input
3 -1 0
Output
2
Explanation
The running sum changes 0 -> 3 -> 2; zero terminates input.
Example 2
Input
0
Output
0
Explanation
There are no values before zero, so the empty sum is zero.