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

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

 

10546๋ฒˆ: ๋ฐฐ๋ถ€๋ฅธ ๋งˆ๋ผํ† ๋„ˆ

๋งˆ๋ผํ† ๋„ˆ๋ผ๋ฉด ๊ตญ์ ๊ณผ ๋‚˜์ด๋ฅผ ๋ถˆ๋ฌธํ•˜๊ณ  ๋ˆ„๊ตฌ๋‚˜ ์ฐธ๊ฐ€ํ•˜๊ณ  ์‹ถ์–ดํ•˜๋Š” ๋ฐฑ์ค€ ๋งˆ๋ผํ†ค ๋Œ€ํšŒ๊ฐ€ ์—ด๋ฆฐ๋‹ค. 42.195km๋ฅผ ๋‹ฌ๋ฆฌ๋Š” ์ด ๋งˆ๋ผํ†ค์€ ๋ชจ๋‘๊ฐ€ ์ฐธ๊ฐ€ํ•˜๊ณ  ์‹ถ์–ดํ–ˆ๋˜ ๋งŒํผ ๋งค๋…„ ๋ชจ๋‘๊ฐ€ ์™„์ฃผํ•ด์™”๋‹ค. ๋‹จ, ํ•œ ๋ช…

www.acmicpc.net


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

๐ŸŽจ Go

// https://www.acmicpc.net/problem/10546
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 runners = map[string]int{}
	for i := 0; i < n; i++ {
		var runner string
		fmt.Fscanln(reader, &runner)
		runners[runner]++
	}
	for i := 0; i < n-1; i++ {
		var finished string
		fmt.Fscanln(reader, &finished)
		runners[finished]--
		if runners[finished] == 0 {
			delete(runners, finished)
		}
	}
	for key := range runners {
		fmt.Fprintln(writer, key)
	}
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    runners = {}
    for i in range(n):
        runner = sys.stdin.readline().rstrip()
        if runner in runners:
            runners[runner] += 1
        else:
            runners[runner] = 1
    for i in range(n-1):
        finished = sys.stdin.readline().rstrip()
        if runners[finished] == 1:
            runners.pop(finished)
        else:
            runners[finished] -= 1
    for i in runners.keys():
        print(i)
728x90
๋Œ“๊ธ€