-
Notifications
You must be signed in to change notification settings - Fork 0
/
P15828.go
74 lines (59 loc) · 1010 Bytes
/
P15828.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Queue
// https://www.acmicpc.net/problem/15828
package main
import (
"bufio"
"container/list"
"os"
"strconv"
)
var br *bufio.Scanner = bufio.NewScanner(os.Stdin)
var bw *bufio.Writer = bufio.NewWriter(os.Stdout)
type Queue struct {
v *list.List
}
func NewQueue() *Queue {
return &Queue{list.New()}
}
func (q *Queue) Push(val interface{}) {
q.v.PushBack(val)
}
func (q *Queue) Pop() interface{} {
front := q.v.Front()
if front == nil {
return nil
}
return q.v.Remove(front)
}
func (q *Queue) Empty() bool {
if q.v.Len() == 0 {
return true
}
return false
}
func (q *Queue) Size() int {
return q.v.Len()
}
func main() {
defer bw.Flush()
queue := *NewQueue()
br.Scan()
N, _ := strconv.Atoi(br.Text())
for {
br.Scan()
Info, _ := strconv.Atoi(br.Text())
if Info == -1 {
break
}
if Info == 0 {
queue.Pop()
} else {
if queue.Size() != N {
queue.Push(Info)
}
}
}
for !queue.Empty() {
bw.WriteString(strconv.Itoa(queue.Pop().(int)) + " ")
}
}