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

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

 

2309๋ฒˆ: ์ผ๊ณฑ ๋‚œ์Ÿ์ด

์•„ํ™‰ ๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ๋‚œ์Ÿ์ด๋“ค์˜ ํ‚ค๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ํ‚ค๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š” ์ž์—ฐ์ˆ˜์ด๋ฉฐ, ์•„ํ™‰ ๋‚œ์Ÿ์ด์˜ ํ‚ค๋Š” ๋ชจ๋‘ ๋‹ค๋ฅด๋ฉฐ, ๊ฐ€๋Šฅํ•œ ์ •๋‹ต์ด ์—ฌ๋Ÿฌ ๊ฐ€์ง€์ธ ๊ฒฝ์šฐ์—๋Š” ์•„๋ฌด๊ฑฐ๋‚˜ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net


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

๐ŸŽจ Go

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

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

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

	heights := []int{}
	var sum int
	for i := 0; i < 9; i++ {
		var h int
		fmt.Fscanln(reader, &h)
		heights = append(heights, h)
		sum += h
	}

	sort.Ints(heights)
	for i := 0; i < 8; i++ {
		for j := i + 1; j < 9; j++ {
			if heights[i]+heights[j] == sum-100 {
				for k := 0; k < 9; k++ {
					if k != i && k != j {
						fmt.Fprintln(writer, heights[k])
					}
				}
				return
			}
		}
	}
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    heights = []
    total = 0
    for i in range(0, 9):
        h = int(sys.stdin.readline())
        heights.append(h)
        total += h

    heights.sort()
    stop = False
    for i in range(0, 8):
        for j in range(i+1, 9):
            if heights[i]+heights[j] == total-100:
                for k in range(0, 9):
                    if k != i and k != j:
                        print(heights[k])
                stop = True
                break
        if stop:
            break
728x90
๋Œ“๊ธ€