๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ฏ | ๋ฐฑ์ค€/๐Ÿ˜€ | Bronze

[Kotlin, B3] ๋ฐฑ์ค€ 3009๋ฒˆ ๋„ค ๋ฒˆ์งธ ์ 

by immgga 2024. 9. 2.

์ถœ์ฒ˜: unsplash.com

 

๋„ค ๋ฒˆ์งธ ์ (3009๋ฒˆ)

Bronze 3

#๊ตฌํ˜„ #๊ธฐํ•˜ํ•™

https://www.acmicpc.net/problem/3009

 

๋ฌธ์ œ ๋‚ด์šฉ

 

 

๋ฌธ์ œ ์ ‘๊ทผ

3๊ฐœ์˜ ์ ์˜ ์ขŒํ‘œ๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์ถ•์— ํ‰ํ–‰ํ•œ ์ง์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋„ค ๋ฒˆ์งธ ์ ์„ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

๋‹ค๋ฅด๊ฒŒ ๋งํ•˜๋ฉด, ์–‘ ๋ณ€์ด ํ‰ํ–‰ํ•œ ์ง์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋„ค ๋ฒˆ์งธ ์ ์„ ๊ตฌํ•ด์•ผ ํ•œ๋‹ค.

 

์ž…๋ ฅ ์˜ˆ์ œ๋“ค์„ ๋ณด๋‹ค ๋ณด๋ฉด ์‰ฝ๊ฒŒ ๊ทœ์น™์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

์ž…๋ ฅ ์˜ˆ์ œ 1์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

5 5
5 7
7 5

// ์ •๋‹ต: 7 7

 

์˜ˆ์ œ ์ž…๋ ฅ 2

30 20
10 10
10 20

// ์ •๋‹ต: 30 10

 

์œ„ 2๊ฐœ์˜ ์ž…๋ ฅ ์˜ˆ์ œ์˜ ์ •๋‹ต์„ ๋ณด๋ฉด ์„ธ ์ขŒํ‘œ์—์„œ 1๊ฐœ์”ฉ ๋“ค์–ด ์žˆ๋Š” ์ขŒํ‘œ๊ฐ’์ด ์ •๋‹ต์ด ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์–‘ ๋ณ€์ด ํ‰ํ–‰ํ•œ ์ •์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ•œ ์ขŒํ‘œ์— x์ถ•๊ณผ ํ‰ํ–‰ํ•œ ์ขŒํ‘œ, y์ถ•์œผ๋กœ ํ‰ํ–‰ํ•œ ์ขŒํ‘œ 1๊ฐœ์”ฉ์ด ํ•„์š”ํ•˜๋‹ค.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์–‘ ๋ณ€์ด ํ‰ํ–‰ํ•œ ์ •์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์–‘ x, y์ขŒํ‘œ ์ˆ˜๊ฐ€ ๋™์ผํ•œ ๊ฐ’ 2๊ฐœ์”ฉ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์•ผ ํ•œ๋‹ค.

 

๊ทธ๋ž˜์„œ ๊ฒฐ๋ก ์€ ์ž…๋ ฅ๋ฐ›์€ ์ขŒํ‘œ์˜ ์ˆ˜ ์ค‘์— 3๊ฐœ์˜ x, y์ขŒํ‘œ๋“ค ์ค‘ ์œ ์ผํ•˜๊ฒŒ ๋‹ค๋ฅธ x, y๊ฐ’์„ ๊ตฌํ•˜๋ฉด ๋œ๋‹ค.

 

 

๋ฌธ์ œ ํ•ด๊ฒฐ ์ฝ”๋“œ

๋”๋ณด๊ธฐ
import java.io.BufferedReader
import java.io.InputStreamReader

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
    val pointsX = mutableMapOf<Int, Int>()
    val pointsY = mutableMapOf<Int, Int>()

    for (i in 1 .. 3) {
        val point = readLine().split(" ").map { it.toInt() }
        if (!pointsX.containsKey(point[0])) pointsX[point[0]] = 1
        else pointsX[point[0]] = pointsX[point[0]]!! + 1

        if (!pointsY.containsKey(point[1])) pointsY[point[1]] = 1
        else pointsY[point[1]] = pointsY[point[1]]!! + 1
    }

    println("${pointsX.filter { it.value == 1 }.keys.first()} ${pointsY.filter { it.value == 1 }.keys.first()}")
}

 

๋ฌธ์ œ ํ’€์ด

x, y์˜ ๊ฐ’์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ๊ธฐ ์œ„ํ•ด map์„ ์ด์šฉํ•ด ์ฃผ์—ˆ๋‹ค. key๋ฅผ ๊ฐ’์œผ๋กœ, value๋ฅผ ๊ฐœ์ˆ˜๋กœ.

map์— ๊ฐ’์„ ์ €์žฅํ•˜๊ณ  ๋‚˜์„œ, map์—์„œ value๊ฐ’์ด 1์ธ key๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋.

 

 

๋ฌธ์ œ ํ•ด๊ฒฐ ๊ณผ์ •

์‰ฌ์›Œ์š”.

๊ทœ์น™ ์ฐพ๊ธฐ๋„ ์‰ฝ๊ณ , ํ‘ธ๋Š” ๋ฐฉ๋ฒ•๋„ ์‰ฝ๋‹ค.

728x90