2023 Huawei od unified exam B paper [Desert island survival] C language implementation

Table of contents 

topic

train of thought

Code


topic

There is a deserted island with only two ports on the left and right. There is only one bridge connecting these two ports. Now a group of people need to escape from the two ports. Some people escape to the right and some people escape to the left. If two people meet, In PK, the person with higher stamina can win against the one with lower stamina. If the stamina is the same, they will die together. Only the winner can continue to escape and reduce the corresponding stamina input. Description A line of non-zero integers separated by spaces
,
positive The number represents escape to the right, and the negative number represents escape to the left.
Output description
Example 1 of the number of people who can escape in the end
:
input

5 10 8 -8 -5
output

2
means that
8 and -8 meet and die together, 10 meets -5, wins and reduces five points of physical strength, and the final escape is 5 and 5, both escape from the right port, output 2

train of thought

Guess you like

Origin blog.csdn.net/misayaaaaa/article/details/131926150