【100 points】【Classification problem】

topic description

【Class placement problem】

Children in two classes of kindergarten got mixed up when queuing up. Each child knows whether he is in the same class as the child in front of him. Please help find out the children in the same class.
The child's number is an integer, and the child who is in the same class as the previous child is represented by Y, and the child who is in a different class is represented by N.

The range of student serial number (0,999], if the input is invalid, it will print ERROR.

Enter a description:

Enter the child's number and whether it is the same class flag separated by spaces.

Output description:

The output is two lines, each line records the number of a class child, the numbers are separated by spaces, and:

1. Numbers should be arranged in ascending order.

2. If there are only children in one class, the second line is blank.

train of thought

  1. First, we need to separate the input strings by spaces to get a list of strings, each element in the list contains the student's number and whether it is in the same class as the previous child ('Y' or 'N').

  2. Then, we need to check whether the input is legal, that is, the student number should be in the range of 1 to 999, and the flag can only be 'Y' or 'N', otherwise return 'ERROR'.

    <

Guess you like

Origin blog.csdn.net/weixin_54707168/article/details/131992675