[Huawei OD machine test 2023] Perfect positioning (C language 100%)

topic description

In the first-person shooting game, the player controls the game character to move left, backward, right, and forward through the four keys of the keyboard A, S, D, and W to complete the walking.

Assume that every time the player presses the keyboard, the game task will move one step in a certain direction. If the player operates the keyboard for a certain number of times and the number of steps in each direction is the same, the game task will definitely return to the original point at this time. The position is the perfect position.

Now given the player's position (for example: ASDA), please change one of the continuous positions so that the original position can become a perfect position. The continuous moves to be replaced can be any moves with the same length.

Returns the smallest possible length of consecutive walks to be replaced.

Returns 0 if the original move itself was a perfect move.

enter description

The input is the movement s represented by the keyboard letter, for example: ASDA

illustrate

1. Position length 1 ≤ s.length ≤ 100000 (that is, the length is not necessarily an even number)
2. s.length is a multiple of 4.
3. s only contains 'A',

Guess you like

Origin blog.csdn.net/shangyanaf/article/details/130471228