Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer in JAVA code. Thank you! (1) Stony Brook University announced that the school will host a Mathematics Olympiad where four SUNY schools (Stony

Please answer in JAVA code. Thank you!

(1) Stony Brook University announced that the school will host a Mathematics Olympiad where four SUNY schools (Stony Brook, Buffalo, Albany, Westbury) are going to compete against each other. Since the team selection is very critical for this competition. Stony Brook University asked you to help in the team selection process. There is a long queue of students from all the four schools. Each student of a school has a different roll number. Whenever a new student will come, he will search for his schoolmate from the end of the queue. As soon as he will find any of the schoolmate in the queue, he will stand behind him, otherwise he will stand at the end of the queue. At any moment, you can ask the students, who is standing in front of the queue, to come and put his name in a red box and remove him from the queue. There are Q operations of one of the following types:

E x y: A new student of school x (1?x?4) whose roll number is y (1?y?50000) will stand in queue according to the method mentioned above.

D: you can ask the student, who is standing in front of the queue, to come and put his name in the red box and remove him from the queue

Now Stony Brook University asked you to tell them the order in which student put their name in the red box. Write a program to print the order.

Note: Number of dequeue operations will never be greater than enqueue operations at any point of time.

Input Format: Take input from a file named in1.txt. The first line contains the number of test cases. The first line of each test case contains an integer Q (1?Q?100000), denoting the number of operations. Next Q lines will contain one of the 2 types of operations.

Output Format: First print the test case number and then for each 2nd type (dequeue) of operation, print two space separated integers, the front student's school number and roll number. Write output on the console.

Sample Input:

2

5

E 1 1

E 2 1

E 1 2

D

D

10

E 1 1

E 2 1

E 3 1

E 4 1

E 1 2

E 2 2

D

D

D

D

Sample Output:

1

1 1

1 2

2

1 1

1 2

2 1

2 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago