The question is similar: (because it was given orally, I understood it for a while)
There are the following rules: (the original question is that a series corresponds to five fingers)
X Y
0 1
1 2
2 3
3 4
4 5
5 4
6 3
7 2
8 1
9 2
10 3
11 4
12 5
13 4
14 3
......
Input an X at will and output a corresponding y
After analysis, I use the following method:
Find the rule Y every 8 groups, so we can make X to 8 get the remainder, and the remainder will be related to Y, as shown below:
Int Gety (const int X)
{
Int temp = x % 8; // 0, 1, 2, 3, 4, 5, 6, 7
If (temp> 4)
Return 8-Temp + 1;
Else
Return temp + 1;
}
Although this can be achieved, the Examiner requiresNo greater than judgmentI have been thinking about it for a long time and have not come up with a more sophisticated approach than "use". It is really depressing. Please kindly advise!