ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

15828๋ฒˆ: Router

์ธํ„ฐ๋„ท์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ปดํ“จํ„ฐ์— ์ธํ„ฐ๋„ท ํšŒ์„ ์„ ์—ฐ๊ฒฐํ•˜๊ฑฐ๋‚˜ Wi-Fi๋ฅผ ์—ฐ๊ฒฐํ•ด์•ผ ํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ์—ฐ๊ฒฐ๋œ ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•ด ์ปดํ“จํ„ฐ์—๋Š” ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ๋งˆ์Œ์— ๋“œ๋Š” ๋…ธ๋ž˜๋‚˜ ๋™์˜์ƒ์ด ์žˆ๋Š” ๊ณณ์—

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ 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
๋Œ“๊ธ€