#CCBCHBON0000033. Switch trong vòng lặp (Switch Inside a Loop)
Switch trong vòng lặp (Switch Inside a Loop)
Switch Inside a Loop
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Process n codes 0..3 left to right. Add 1, 2, or 3 for corresponding codes; the first 0 terminates processing without contributing. If no 0 occurs, process all n. A switch-case break does not exit the surrounding loop.
Input
First n (0<=n<=10000), then exactly n codes from [0,3].
Output
Print the sum of codes preceding the first zero.
Subtasks
-
Subtask 1 (20%): ; .
-
Subtask 2 (30%): ; .
-
Subtask 3 (50%): ; .
Examples
Example 1
Input:
5
1 2 0 3 3
Output:
3
Explanation:
Only codes before the first zero contribute. Result: 3.
Example 2
Input:
4
1 2 3 1
Output:
7
Explanation:
Only codes before the first zero contribute. Result: 7.
Example 3
Input:
0
Output:
0
Explanation:
Only codes before the first zero contribute. Result: 0.