結果

問題 No.32 貯金箱の憂鬱
ユーザー yo-kondoyo-kondo
提出日時 2019-01-03 17:07:50
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 272 ms / 5,000 ms
コード長 1,475 bytes
コンパイル時間 14,352 ms
コンパイル使用メモリ 423,116 KB
実行使用メモリ 50,540 KB
最終ジャッジ日時 2023-09-30 13:24:11
合計ジャッジ時間 18,707 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
50,280 KB
testcase_01 AC 263 ms
50,540 KB
testcase_02 AC 266 ms
50,148 KB
testcase_03 AC 265 ms
50,236 KB
testcase_04 AC 267 ms
50,176 KB
testcase_05 AC 269 ms
50,332 KB
testcase_06 AC 271 ms
50,404 KB
testcase_07 AC 265 ms
50,380 KB
testcase_08 AC 265 ms
50,400 KB
testcase_09 AC 272 ms
50,520 KB
testcase_10 AC 267 ms
50,296 KB
testcase_11 AC 265 ms
50,260 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:19:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

// No.32 貯金箱の憂鬱
// https://yukicoder.me/problems/no/32

package no01.yukicoder.no32

/** インプットデータ */
data class InputData(
    /** 100 円硬貨の枚数 */
    val yen100: Int,
    /** 25 円硬貨の枚数 */
    val yen25: Int,
    /** 1 円硬貨の枚数 */
    val yen1: Int
)

/**
 * エントリポイント
 */
fun main(args: Array<String>) {
    val input = getStandardInput()
    println(bank(input))
}

/**
 * 硬貨の枚数が最も少なくなるように両替したとき、最小となる硬貨の数を返します。
 */
fun bank(input: List<String>): Int {
    val data = createInputData(input)

    var i100 = data.yen100
    var i25 = data.yen25
    var i1 = data.yen1

    if (i1 != 0) {
        i25 += i1 / 25
        i1 %= 25
    }
    if (i25 != 0) {
        i100 += i25 / 4
        i25 %= 4
    }
    if (i100 != 0) {
        i100 %= 10
    }
    return i1 + i25 + i100
}

/**
 * 標準入力から取得した文字列をInputDataに変換して返します。
 */
fun createInputData(input: List<String>): InputData {
    return InputData(
        input[0].toInt(),
        input[1].toInt(),
        input[2].toInt()
    )
}

/**
 * 標準入力から文字列を全て取得します。
 */
fun getStandardInput(): List<String> {
    val lines = mutableListOf<String>()
    var line: String?
    line = readLine()
    while (line != null) {
        lines.add(line)
        line = readLine()
    }
    return lines
}
0