11390 - zuma   

Description

This problem asks you:

 

Step 1: Create a linked list to store a sequence of colors.

Step 2: Insert a node at an appropriate position.

Step 3: Check nodes adjacent to the inserted node on both left and right sides.

Step 4: Delete the checked node if its color is the same as the inserted node.

Step 5: Do Step 3 and Step 4 again until the color of checked node is different.

 

Note:

  • Color = {BLUE, GREEN, RED, HEAD, TAIL}, but HEAD and TAIL are only used to create the Head node and the Tail node in the beginning.
  • Each statement for inserting contains a command and a position. Translate the command to the corresponding Color and insert it if the position is valid.
  • You cannot insert a node after the Tail node.

 

For example, if the input is

r r g r e

3

r 1

b 4

g 6

 

 

The first sequence is r r g r e, so a linked list is created as

For the statement (r, 1):

Step 2:

Step 3 ~ Step 5 (on the left side):

Step 3 ~ Step 5 (on the right side):

For the statement (b, 4):

 

Step 2:

Step 3 ~ Step 5:

For the statement (g, 6):

 

Due to illegal position, ignore this statement.

Finally, the output should be red green red blue.

 

For OJ submission:

 

       Step 1. Submit only your function.c into the submission block. (Please choose c compiler)

 

       Step 2. Check the results and debug your program if necessary.

Input

The input contains 2 parts:

 

  1. A sequence of initial colors as the linked list, except the last one, which is e.

 

  1. A number N means the number of operations, and each of the next N lines contains a pair of numbers (X, Y). X is the Color and Y is the position at which you are asked to insert a new node.

Output

The output contains the sequence of the remaining colors.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11390.c

Partial Judge Header

11390.h

Tags




Discuss