#CCBCHMUOI0000032. So sánh hai cách viết case (Comparing Case Implementations)
So sánh hai cách viết case (Comparing Case Implementations)
Comparing Case Implementations
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given x in 0..3, consider switch(x) with labels 3, 2, 1, 0 in descending order. Each label 3 through 1 adds 1 to a counter initially zero and falls through; case 0 breaks. Print the final counter value. This is equivalent to directly printing x.
Input
One integer x.
Output
Print the number of increments performed in the switch.
Subtasks
- Subtask 1 (20%): 0 <= x <= 1.
- Subtask 2 (30%): 0 <= x <= 2.
- Subtask 3 (50%): 0 <= x <= 3.
Examples
Example 1
Input
3
Output
3
Explanation
Starting at case 3 performs three increments before case 0 breaks.
Example 2
Input
0
Output
0
Explanation
Entry at case 0 breaks immediately without incrementing.