2023 Huawei OD Machine Test Paper C [Xiao Ming’s Lucky Number] C Language Implementation

Table of contents

topic

Ideas

Code


topic

Xiao Ming is playing a game. The rules of the game are as follows: Before the game starts, Xiao Ming stands at the origin of the coordinate axis (the coordinate value is 0) and is given a set of instructions and a lucky number.Each instruction is an integer. Xiao Ming follows the instruction to advance the specified number of steps or to go back the specified number of steps. Forward means walking in the positive direction of the coordinate axis, and backward means walking in the negative direction of the coordinate axis.
The lucky number is an integer. If an instruction is exactly equal to the lucky number, Xiao Ming will advance by +1. For example:
The lucky number is 3, and the command is [2,3,0,-5]
The command is 2, which means moving forward 2 steps;
The command is 3, which is exactly the same as the lucky number, 3+1=4 steps forward;
The command is 0, which means staying still, neither moving forward nor going back.
The command is -5, which means taking 5 steps back.
Please calculate the maximum coordinate value of Xiao Ming’s position during the entire game


Enter description
Enter 1 number in the first line, representing the total number of instructions n (1 <= n <= 100)

Enter a number in the second line, representing the lucky number m (-100 <= m <= 100)

The third line of input

Guess you like

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