Circular queue, final state MEDIUM Liste stive cozi (BAC) 25 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

A natural number `N` is read, followed by `N` operations applied to a **circular queue** of capacity `1000`, implemented with an array and two indices (`front`, `rear`). Each operation is on its own line and can be: - `1 x` -- add the value `x` to the queue (if there is room; otherwise ignore); - `2` -- remove the element at the front of the queue (if the queue is empty, ignore). After all operations have been applied, print the **contents of the queue**, from front to back, values separated by single spaces. If the queue is empty at the end, print the word `VIDA`. Use a plain array and modulo `1000` arithmetic. Do not use STL containers.

Input format

Input input.txt

The first line contains the number `N`. The next `N` lines each contain one operation in the formats described above. - `0 <= N <= 1000`; - values `x` are natural numbers, `0 <= x <= 1_000_000`; - operations are given in the order they should be applied.

Output format

Output output.txt

The program prints to standard output either the queue elements separated by spaces, or the word `VIDA`, followed by a newline.

Example

input
6

1 5

1 8

1 3

2

1 9

1 2
output
8 3 9 2

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more