You have to perform N operations on the queue. The operations are of following type:

−1 in place of deleted element.

Constraints:
1≤x≤100

Format of the input file:
First line : N.
Next N lines : One of the above operations

Format of the output file:
For each enqueue operation print the new size of the queue. And for each dequeue operation print two integers, deleted element (−1, if queue is empty) and the new size of the queue.

该功能就是先进先出,和栈唯一不相同的就是 queue = queue[1:] 把前面的一个元素去掉

package main

import "fmt"
var queue []int

func main() {
	//fmt.Println("Hello World!")
	queue = make([]int,0,0)
	var inputCount int
	fmt.Scanln(&inputCount)
	
	var flag string
	var value int
	var queueLength int
	for i:=0;i<inputCount;i++{
	    fmt.Scanln(&flag,&value)
	    queueLength = len(queue)
	    if flag == "E" {
	        queue = append(queue,value)
	        queueLength = len(queue)
	        fmt.Println(queueLength)
	    }else if flag == "D"{
	       if queueLength ==0 {
	           fmt.Println("-1 0")
	       }else{
	           exitvalue:=queue[0]
	           queue = queue[1:]
	           queueLength = len(queue)
	           fmt.Println(exitvalue,queueLength)
	       }
	    }
	}	
}

  

相关文章:

  • 2022-12-23
  • 2021-07-21
  • 2022-01-05
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-03-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-02-03
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
相关资源
相似解决方案