Huawei OD machine test real questions - unhappy children - 2023 OD unified test (B paper)

Title description:

A batch of rocking cars have been added to the playground, which are very popular with children, but 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. The children who do not play in the end will be very unhappy. Please count the number of unhappy children based on the coming and going of the children today.

1. The number of rocking cars is N, and the range is: 1≤N<10;

2. Each child corresponds to a code, which is a non-repeating number. Today's children's comings and goings can be represented by codes: 1 1 2 3 2 3. (If the child has a free rocking car before leaving, it means leaving after playing; regardless of the child's multiple playing conditions). Number of children<=100

3. The title ensures that all input data is normal and the range meets the above description.

Enter a description:

The first line: the number of rocking cars

The second line: the situation of children coming and going

Output description:

Return the number of unhappy children

Supplementary note:

Example 1

enter:

1
1 2 1 2

output:

0

illustrate:

First row, 1 rocking car

The second line, come on the 1st, come on the 2nd (queue) go on the 1st, go on the 2nd (after the 1st walks, the rocking car is free, so leave after playing)

Example 2

enter:

1
1 2 2 3 1 3

output:

1

illustrate:

First row, 1 rocking car

second line

Guess you like

Origin blog.csdn.net/2301_76848549/article/details/131472771