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

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

 

10815๋ฒˆ: ์ˆซ์ž ์นด๋“œ

์ฒซ์งธ ์ค„์— ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10,

www.acmicpc.net


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

๐ŸŽจ Go

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 cards = map[int]int{}
	for i := 0; i < n; i++ {
		var input int
		if i == n-1 {
			fmt.Fscanln(reader, &input)
		} else {
			fmt.Fscan(reader, &input)
		}
		cards[input]++
	}

	var m int
	fmt.Fscanln(reader, &m)

	for i := 0; i < m; i++ {
		var num int
		fmt.Fscanf(reader, "%d ", &num)
		fmt.Fprintf(writer, "%s ", hasCard(cards, num))
	}
}

func hasCard(cards map[int]int, num int) string {
	if cards[num] != 0 {
		return "1"
	}
	return "0"
}

๐ŸŽจ Python3

import sys

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    cards = {}
    cards_inputs = list(map(int, sys.stdin.readline().split()))
    for i in cards_inputs:
        cards[i] = 1

    m = int(sys.stdin.readline())
    num_inputs = list(map(int, sys.stdin.readline().split()))
    results = []
    for i, v in enumerate(num_inputs):
        if cards.get(v):
            print(1, end=' ')
        else:
            print(0, end=' ')
        if i == m-1:
            print()
728x90
๋Œ“๊ธ€