2023 Huawei OD Machine Test Paper B [Unhappy Children] C Language

Table of contents

topic

Ideas

Code


topic

A number of rocking cars have been added to the playground, which are very popular with children. However, each rocking car can only be used by one child at a time. If there is no free rocking car, you need to wait in line or leave directly. In the end, you will not be able to play. The children will be very unhappy.
Please count the number of unhappy children based on the coming and going of children today.
1. The number of rocking cars is N, and the range is: 1 <= N < 10;
2. Each child corresponds to a code, and the code is a non-repeating number. , the coming and going of children today can be expressed using coding as: 1 1 2 3 2 3. (If the child has a free rocker before leaving, it means that the child left after playing; the situation of the child playing multiple times is not considered). Number of children ≤ 100

3. The question ensures that all input data are free of abnormalities and the range meets the above instructions.
Input description
Line 1: Number of rocking cars

Second line:
Output description
of children’s coming and going . Returns the number of unhappy children.

Example 1:
Input

1
1 2

1 2
output

0
Description
First row, 1 rocking car, second row, No. 1 comes and No. 2 comes (queuing) No. 1 goes and No. 2 goes (the car is free after No. 1 leaves, so leave after playing)

</

おすすめ

転載: blog.csdn.net/misayaaaaa/article/details/133144202