#CCBCHMUOI0000030. Dấu của trạng thái fallthrough (Fallthrough State Trace)
Dấu của trạng thái fallthrough (Fallthrough State Trace)
Fallthrough State Trace
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
A C program starts with a = 0 and executes switch(k) with case 1: a += 1; case 2: a += 2; break; default: a += 4;. There is deliberately no break between cases 1 and 2. Print the final value of a.
Input
One integer k.
Output
Print the final integer value of a after the switch.
Subtasks
- Subtask 1 (20%): k = 1.
- Subtask 2 (30%): k is 1 or 2.
- Subtask 3 (50%): -10 <= k <= 10.
Examples
Example 1
Input
1
Output
3
Explanation
Starting at 0, case 1 adds 1 then falls through to case 2, adding 2, so the answer is 3.
Example 2
Input
2
Output
2
Explanation
Entry at case 2 adds only 2 and then breaks.