- import java.util.*;
-
- public class MINtech {
- public static void main(String[] args) {
-
- // Create a scanner object to read input from the user
- Scanner sc = new Scanner(System.in);
- // Read a line of input from the user
- String str = sc.nextLine();
-
- // Create a queue to store integers
- Queue <Integer > queue = new LinkedList< >();
-
- // Split the input line into an array of queries using commas as a delimiter
- String[] queries = str.split(",");
-
- for (int i = 0; i < queries.length; i++) {
- // Get a single query from the array
- String query = queries[i];
- // Split the query into parts using space as a delimiter
- String[] parts = query.split(" ");
- // Parse the first part of the query as an integer to determine the type of operation
- int type = Integer.parseInt(parts[0]);
-
- if (type == 1) {
- // Parse the second part of the query as an inte
- int x = Integer.parseInt(parts[1]);
- // Add the integer to the queueger
- queue.offer(x);
- } else if (type == 2) {
- if (!queue.isEmpty()) {
- // Remove the element at the front of the queue if the queue is not empty
- queue.poll();
- }
- } else if (type == 3) {
- if (!queue.isEmpty()) {
- // Print the element at the front of the queue if the queue is not empty
- System.out.println(queue.peek());
- }
- }
- }
- // Close the scanner to release system resources
- sc.close();
- }
- }
No comments:
Post a Comment