#CCBCHHAI0000003. Lặp đến lần đầu gặp 0 (Sum Until First Zero)
Lặp đến lần đầu gặp 0 (Sum Until First Zero)
Sum Until First Zero
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Read integers in order and sum all values before the first zero. The zero is a terminator and is not included in the sum. Print the sum even if the first value is zero.
Input
A sequence ending with zero; no earlier value is zero. At most values precede the terminator.
Output
Print the sum of all integers preceding the zero; the result fits in signed 64-bit integer.
Subtasks
- Subtask 1 (20%): At most 5 values before zero, each with absolute value at most 10.
- Subtask 2 (30%): At most 100 values before zero, each with absolute value at most 1000.
- Subtask 3 (50%): At most values before zero, each with absolute value at most .
Examples
Example 1
Input
5 -2 0
Output
3
Explanation
Add 5 then -2 to obtain 3; the zero ends the sequence.
Example 2
Input
0
Output
0
Explanation
The first value is the terminator; the sum remains zero.