|
@@ -0,0 +1,84 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "bufio"
|
|
|
|
+ "fmt"
|
|
|
|
+ "os"
|
|
|
|
+ "strconv"
|
|
|
|
+ "strings"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+del
|
|
|
|
+add 12
|
|
|
|
+del
|
|
|
|
+add 10
|
|
|
|
+add 9
|
|
|
|
+del
|
|
|
|
+del
|
|
|
|
+del
|
|
|
|
+add 10
|
|
|
|
+del
|
|
|
|
+add 1
|
|
|
|
+add 8
|
|
|
|
+add 20
|
|
|
|
+add 1
|
|
|
|
+add 11
|
|
|
|
+add 2
|
|
|
|
+del
|
|
|
|
+del
|
|
|
|
+del
|
|
|
|
+del
|
|
|
|
+*/
|
|
|
|
+func main() {
|
|
|
|
+ var cQueue = Constructor()
|
|
|
|
+ input := bufio.NewScanner(os.Stdin)
|
|
|
|
+ for input.Scan() {
|
|
|
|
+ line := input.Text()
|
|
|
|
+ if !strings.HasPrefix(line, "add ") && !strings.HasPrefix(line, "del") {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if strings.HasPrefix(line, "add ") {
|
|
|
|
+ var digitStr = line[4:]
|
|
|
|
+ var digit, _ = strconv.Atoi(digitStr)
|
|
|
|
+ cQueue.AppendTail(digit)
|
|
|
|
+ println("null")
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if strings.HasPrefix(line, "del") {
|
|
|
|
+ var digit = cQueue.DeleteHead()
|
|
|
|
+ println(digit)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(cQueue.Stack1, "---", cQueue.Stack2)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type CQueue struct {
|
|
|
|
+ Stack1 []int
|
|
|
|
+ Stack2 []int
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func Constructor() CQueue {
|
|
|
|
+ return CQueue{}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (this *CQueue) AppendTail(value int) {
|
|
|
|
+ this.Stack1 = append(this.Stack1, value)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (this *CQueue) DeleteHead() int {
|
|
|
|
+ if len(this.Stack1) == 0 {
|
|
|
|
+ return -1
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var value int
|
|
|
|
+
|
|
|
|
+ this.Stack2 = append(this.Stack2, this.Stack1[0])
|
|
|
|
+ value = this.Stack2[0]
|
|
|
|
+ this.Stack1 = this.Stack1[1:]
|
|
|
|
+ this.Stack2 = this.Stack2[1:]
|
|
|
|
+
|
|
|
|
+ return value
|
|
|
|
+}
|