#CCBCHMUOI0000031. Fallthrough có điều kiện (Conditional Fallthrough)
Fallthrough có điều kiện (Conditional Fallthrough)
Conditional Fallthrough
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Start with s = 0. Execute switch(k): case 1 adds 1 and breaks if x > 0; case 2 adds 2 without a break; default adds 3. There is no break between case 2 and default. Print final s.
Input
One line contains integers k and x.
Output
Print the final integer s after leaving the switch.
Subtasks
- Subtask 1 (20%): k = 1 and 1 <= x <= 10.
- Subtask 2 (30%): k is 1 or 2, -10 <= x <= 10.
- Subtask 3 (50%): -10 <= k,x <= 10.
Examples
Example 1
Input
1 0
Output
6
Explanation
Case 1 adds 1; the condition is false, then case 2 adds 2 and default adds 3, yielding 6.
Example 2
Input
1 1
Output
1
Explanation
After adding 1, x > 0 triggers break, so the remaining cases are skipped.