CC31F-1 Lesson
CC31F-1 Lesson
Robot World
Farmer John's storage is a very tall but narrow room that only
one haybale can fit with respect to the width and the length. So SAMPLE INPUT
the haybales can only be stored by stacking them starting from
the floor. Initially the storage is empty and there are haybales 20
numbered starting from 1 in the warehouse. ADD
ADD Simulation Problem
FJ has a robot equipped with one arm that can hold one haybale. ADD
He controls the robot with two commands: ADD and REMOVE. With ADD
ADD command, the robot takes the next haybale in the warehouse REMOVE
and puts it on top of the haybales in the storage. When it ADD
receives REMOVE command it takes the haybale on the top in the ADD
storage and carries it to the barn. REMOVE
REMOVE
At the end of the week, FJ wants to learn the status of the REMOVE
storage in terms of the list of the haybales. Your program will ADD
help FJ to find out the list of the haybales. For example, given ADD
the sequence of FJ's commands throughout the week, the list of REMOVE
the haybales in the storage will be as follows: REMOVE
REMOVE
Command Storage REMOVE
------- ---------- ADD
ADD 1 ADD
ADD 1 2 REMOVE
ADD 1 2 3 ADD
ADD 1 2 3 4
REMOVE 1 2 3
ADD 1 2 3 5
ADD 1 2 3 5 6
REMOVE 1 2 3 5
REMOVE 1 2 3
REMOVE 1 2 Stack Data Structure:
ADD 1 2 7
ADD 1 2 7 8 Operations
REMOVE 1 2 7 push(x) O(1)
REMOVE 1 2 x = pop() O(1)
REMOVE 1 size() O(1)
REMOVE
ADD 9
ADD 9 10
REMOVE 9
ADD 9 11
Finally, the haybales numbered 9 and 11 will remain in the
storage.
INPUT FORMAT
20
ADD
ADD
ADD
ADD
REMOVE
ADD
ADD
REMOVE
REMOVE
REMOVE
ADD
ADD
REMOVE
REMOVE
REMOVE
REMOVE
ADD
ADD
REMOVE
ADD
OUTPUT FORMAT
2
9
11
Register 1: 4 5 2
Register 2: 3 5 1 3
Register 3: 1 5 2
INPUT FORMAT
3
C 1
C 5
C 3
R 3
C 2
R 3
C 5
R 2
C 4
C 1
R 3
C 3
R 2
R 1
C 5
C 2
R 2
R 2
R 1
R 1
OUTPUT FORMAT
SAMPLE OUTPUT
3 4 5 2
4 3 5 1 3
3 1 5 2
Line Dancing
[ Memory: 16 MB, CPU: 1 sec ]
There are N students conveniently numbered 1..N forming a line. The Read/understand the problem and share your
line is initially empty, and students join one by one to the left or solution idea.
right side. Sometimes, a number of students on the left or right side
of the line leave.
The students enter the line in numerical order 1..N. Once a student
leaves the line they never re-enter it.
Determine the order of the students in the line after all input has
been processed. Print the answer from left to right. The answer is
guaranteed to be non-empty.
INPUT FORMAT
Line 1..?: Print the numbers of the students in the line from left to
right, one number per line
SAMPLE INPUT
7
A L
A R
A L
A R
D R 2
A R
D L 1
SAMPLE OUTPUT
1
5
OUTPUT DETAILS