[Huawei OD test questions] 100% pass rate for card players (java) [2023 (B volume) 100 points]

poker player

topic description

Given an integer array of length N, which represents the score of a player's choice of cards in N rounds, and the
player chooses cards based on the rules, please calculate the highest total score he can get after all rounds.
The selection rules are as follows:


In each round, players can choose to obtain the cards of this round, and their total score plus the score of this round will be their new total score. The total score is restored to the total score before 3 rounds. If the current round is less than or equal to 3, the total score will be set to 0. The
initial total score of the player is 0, and must participate in each round in turn

enter description

The first line is a lowercase comma-separated string
indicating the card score of N rounds
1 <= N <= 20 The score value is an integer [-100,100]
regardless of the format

output description

The highest total score a player can earn after all rounds

example one

enter

1,-5,-6,4,3,6,-2

output

11

illustrate

A total of 7 rounds of cards,
the total score of the first round is 1,
the second round is not selected, the total score of the round is 0,
the third round is not selected, the total score of the round is 0,
the fourth round is selected The total score of this round is 4.
The fifth round is selected. The total score of this round is 7
.

Guess you like

Origin blog.csdn.net/weixin_45541762/article/details/132395002