ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/15828
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var queue []int
for {
var input int
fmt.Fscanln(reader, &input)
if input == -1 {
break
} else if input == 0 {
queue = queue[1:]
} else {
if len(queue) < n {
queue = append(queue, input)
}
}
}
if len(queue) == 0 {
fmt.Fprintln(writer, "empty")
} else {
for i := 0; i < len(queue); i++ {
fmt.Fprintf(writer, "%d ", queue[i])
}
}
}
๐จ Python3
# https://www.acmicpc.net/problem/15828
import sys
import queue
if __name__ == "__main__":
n = int(sys.stdin.readline())
q = queue.Queue()
while True:
input = int(sys.stdin.readline())
if input == -1:
break
elif input == 0:
q.get()
else:
if q.qsize() < n:
q.put(input)
if q.qsize() == 0:
print("empty")
else:
while not q.empty():
print("{} ".format(q.get()), end='')
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 14606๋ฒ / ํผ์ (Small) [Go][Python3] (0) | 2021.03.13 |
---|---|
BOJ / 2847๋ฒ / ๊ฒ์์ ๋ง๋ ๋์ค์ด [Go][Python3] (0) | 2021.03.12 |
BOJ / 17212๋ฒ / ๋ฌ๋๋ผ ํ ๋ผ๋ฅผ ์ํ ๊ตฌ๋งค๋๊ธ ์ง๋ถ ๋์ฐ๋ฏธ [Go][Python3] (0) | 2021.03.10 |
BOJ / 1010๋ฒ / ๋ค๋ฆฌ ๋๊ธฐ [Go][Python3] (0) | 2021.03.09 |
BOJ / 8394๋ฒ / ์ ์ [Go][Python3] (0) | 2021.03.08 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- dfs
- python3
- BOJ
- MongoDB
- Macbook pro 2012 mid 13
- dp
- ๋งฅ๋ถํ๋ก
- baekjoon
- AWS
- ํ๋ก์ด๋์์ฌ
- ๋ชฝ๊ณ ๋๋น
- ๋ถํ ์ ๋ณต
- Golang
- ์๊ฐ๊ต์ฒด
- go
- ballet
- ์๊ณ ๋ฆฌ์ฆ
- ์คํ
- ์๋ฐ
- ์ด๋ถํ์
- ๋ธ๋ฃจํธํฌ์ค
- ๋ฐ๋
- ํ
- ๋ฐฑ์ค
- java
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถ
- BFS
- Algorithm
- ํด์๋งต
- Total
- Today
- Yesterday