#CCBCHHAI0000038. Lọc mã có xác nhận (Even Code Filter with Stop)
Lọc mã có xác nhận (Even Code Filter with Stop)
Even Code Filter with Stop
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Read an integer stream until the first -1. Compute the sum of even integers in the closed interval [0,100] occurring before termination. Ignore odd integers, other negatives and values above 100. Zero is valid and even but adds nothing. Practice combining a do-while, filtering with if, and continue.
Input
A whitespace-separated sequence of integers ending in -1, with no value after it. All preceding values differ from -1.
Output
Print one integer: the sum of all even x in [0,100] before -1.
Subtasks
- Subtask 1 (20%): At most 5 values including -1; each in [-10,10].
- Subtask 2 (30%): At most 100 values including -1; each in [-100,100].
- Subtask 3 (50%): At most 10000 values including -1; each in [-1000,1000].
Examples
Example 1
Input
2 3 100 102 -4 0 -1
Output
102
Explanation
2, 100 and 0 are valid; 3 is odd, 102 is too large, and -4 is negative. The sum is 102.
Example 2
Input
-1
Output
0
Explanation
The first value is the terminator; no value is added.