結果

問題 No.32 貯金箱の憂鬱
ユーザー yo-kondoyo-kondo
提出日時 2018-03-24 16:06:31
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 268 ms / 5,000 ms
コード長 980 bytes
コンパイル時間 11,754 ms
コンパイル使用メモリ 413,312 KB
実行使用メモリ 50,692 KB
最終ジャッジ日時 2023-09-30 13:08:14
合計ジャッジ時間 16,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
50,316 KB
testcase_01 AC 267 ms
50,692 KB
testcase_02 AC 268 ms
50,324 KB
testcase_03 AC 261 ms
50,324 KB
testcase_04 AC 264 ms
50,620 KB
testcase_05 AC 265 ms
50,692 KB
testcase_06 AC 264 ms
50,284 KB
testcase_07 AC 267 ms
50,668 KB
testcase_08 AC 264 ms
50,476 KB
testcase_09 AC 266 ms
50,336 KB
testcase_10 AC 265 ms
50,304 KB
testcase_11 AC 262 ms
50,484 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:7:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package yukicoder.no32

/**
 * エントリポイント
 * @param args コマンドライン引数
 */
fun main(args: Array<String>) {
    val in1 = readLine()
    val in2 = readLine()
    val in3 = readLine()
    println(bank(in1, in2, in3))
}

/**
 * 硬貨の枚数が最も少なくなるように両替したとき、最小となる硬貨の数を返します。
 * @param yen100 100円硬貨の枚数
 * @param yen25 25円硬貨の枚数
 * @param yen1 1円硬貨の枚数
 * @return 最小となる硬貨の枚数
 */
fun bank(yen100: String?, yen25: String?, yen1: String?): String {
    if (yen100 == null || yen25 == null || yen1 == null) {
        return ""
    }
    var i100 = yen100.toInt()
    var i25 = yen25.toInt()
    var i1 = yen1.toInt()

    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).toString()
}
0