Print Queue Contents
EasyPractice library · +10 XPqueuesimulationbasic programming
You are given a sequence of integers. You need to process this sequence as if it were a queue. All elements are added to the queue in the order they appear in the input. After all elements have been added, print the elements of the queue in the order they are dequeued (First-In, First-Out).
Input
The first line contains an integer N, the number of elements. The second line contains N space-separated integers.
Output
Print the N integers in the order they would be dequeued from a queue.
Constraints
1 <= N <= 1000 Elements are integers between -1000 and 1000.
Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests
Example 1
Input
5 10 20 30 40 50
Output
10 20 30 40 50
Elements are enqueued in order and then dequeued in the same order.
Example 2
Input
3 5 -2 8
Output
5 -2 8
Handles negative numbers correctly.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 10 20 30 40 50
Example 2 input
3 5 -2 8