Algorithm

Kotlin ์ฝ”ํ‹€๋ฆฐ ๋ฐฑ์ค€ 2659 ์‹ญ์ž์นด๋“œ ๋ฌธ์ œ

๋…ธ๋ฃจ๋ฃฝ 2022. 12. 16. 16:57

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

 

2659๋ฒˆ: ์‹ญ์ž์นด๋“œ ๋ฌธ์ œ

์ž…๋ ฅ์€ ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ง€๋ฉฐ, ์ด ํ•œ ์ค„์€ ์นด๋“œ์˜ ๋„ค ๋ชจ์„œ๋ฆฌ์— ์”Œ์—ฌ์žˆ๋Š” 1 ์ด์ƒ 9 ์ดํ•˜์˜ ์ˆซ์ž 4๊ฐœ๊ฐ€ ์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ ์ž…๋ ฅ๋œ๋‹ค. ๊ฐ ์ˆซ์ž ์‚ฌ์ด์—๋Š” ๋นˆ์นธ์ด ํ•˜๋‚˜ ์žˆ๋‹ค.

www.acmicpc.net

 

๋„ค ์ž๋ฆฌ ์ˆ˜๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ์ž‘์€ ์ˆ˜์ธ ์‹œ๊ณ„์ˆ˜๋ฅผ ๊ตฌํ•ด์„œ,

๋ชจ๋“  ์‹œ๊ณ„์ˆ˜๋“ค ์ค‘์—์„œ ๋ช‡ ๋ฒˆ์งธ๋กœ ์ž‘์€ ์‹œ๊ณ„์ˆ˜์ธ์ง€ ์นด์šดํŠธํ•ด์ฃผ๋ฉด ๋œ๋‹ค!

 

import java.lang.Integer.min

/**
 * ์‹ญ์ž์นด๋“œ ๋ฌธ์ œ
 * https://www.acmicpc.net/problem/2659
 */

private var card = 0
private var answer = 0

private fun getClockNum(num: Int): Int {
    var temp = num
    var result = num
    repeat(4) {
        temp = temp % 1000 * 10 + temp / 1000
        result = min(result, temp)
    }
    return result
}

private fun solution() {
    for (i in 1111..getClockNum(card)) {
        if (getClockNum(i) == i) answer++
    }
    println(answer)
}

private fun input() = with(System.`in`.bufferedReader()) {
    card = readLine().replace(" ", "").toInt()
    close()
}

fun main() {
    input()
    solution()
}