#K3191. Printer Queue Simulation
Printer Queue Simulation
Printer Queue Simulation
You are required to implement a simulation of a printer queue management system. The printer queue supports the following operations:
- ENQUEUE jobName priority: Add a new print job with the given
jobName
(a string) andpriority
(an integer). Jobs with higher priority values are processed before lower priority ones. In case two jobs have equal priority, the job that was enqueued earlier is processed first. This condition can be formally expressed as: \(\text{If } priority_i = priority_j, \text{ then job } i \text{ (inserted earlier) is processed before job } j.\)</p> - DEQUEUE: Remove and output the job name with the highest priority. If the queue is empty, output "No jobs".
- SIZE: Output the number of jobs currently in the queue.
- PEEK: Output the job name with the highest priority without removing it. If the queue is empty, output "No jobs".
All operations must be processed sequentially. Input is given via standard input and output should be printed to standard output.
inputFormat
The first line of input contains a single integer N
, the number of operations.
Each of the following N
lines contains one operation in one of the following formats:
ENQUEUE jobName priority
DEQUEUE
SIZE
PEEK
All input is read from standard input.
outputFormat
For each operation that produces an output (DEQUEUE
, SIZE
, or PEEK
), print the result on a new line in the order the commands are processed. For DEQUEUE
and PEEK
operations, if the queue is empty, output No jobs
.
All output should be printed to standard output.
## sample5
ENQUEUE Job1 2
ENQUEUE Job2 1
DEQUEUE
SIZE
PEEK
Job1
1
Job2
</p>