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

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

 

1822๋ฒˆ: ์ฐจ์ง‘ํ•ฉ

์ฒซ์งธ ์ค„์—๋Š” ์ง‘ํ•ฉ A์˜ ์›์†Œ์˜ ๊ฐœ์ˆ˜ n(A)์™€ ์ง‘ํ•ฉ B์˜ ์›์†Œ์˜ ๊ฐœ์ˆ˜ n(B)๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. (1 ≤ n(A), n(B) ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ง‘ํ•ฉ A์˜ ์›์†Œ๊ฐ€, ์…‹์งธ ์ค„์—๋Š” ์ง‘ํ•ฉ B์˜ ์›์†Œ

www.acmicpc.net


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

๐ŸŽจ Go

// https://www.acmicpc.net/problem/1822
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var aCount, bCount int
	fmt.Fscanln(reader, &aCount, &bCount)
	var elements = map[int]bool{}
	for i := 0; i < aCount; i++ {
		var elem int
		fmt.Fscanf(reader, "%d ", &elem)
		elements[elem] = true
	}
	for i := 0; i < bCount; i++ {
		var elem int
		fmt.Fscanf(reader, "%d ", &elem)
		delete(elements, elem)
	}
	fmt.Fprintln(writer, len(elements))
	var elemArray []int
	for key := range elements {
		elemArray = append(elemArray, key)
	}
	sort.Ints(elemArray)
	arrToStr := fmt.Sprint(elemArray)
	fmt.Fprint(writer, arrToStr[1:len(arrToStr)-1])
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/1822
import sys

if __name__ == "__main__":
    a_count, b_count = list(map(int, sys.stdin.readline().split()))
    a = set(map(int, sys.stdin.readline().split()))
    b = set(map(int, sys.stdin.readline().split()))
    diff = a.difference(b)
    result = sorted(list(diff))
    if len(result) == 0:
        print(0)
    else:
        print(len(result))
        for i in result:
            print("{} ".format(i), end='')
        print()
728x90
๋Œ“๊ธ€