結果

問題 No.32 貯金箱の憂鬱
ユーザー kitamoto0407kitamoto0407
提出日時 2024-03-17 08:21:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 1,765 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 76,980 KB
実行使用メモリ 54,112 KB
最終ジャッジ日時 2024-03-17 08:22:06
合計ジャッジ時間 4,416 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,080 KB
testcase_01 AC 54 ms
54,104 KB
testcase_02 AC 55 ms
54,108 KB
testcase_03 AC 57 ms
54,112 KB
testcase_04 AC 55 ms
54,104 KB
testcase_05 AC 57 ms
54,100 KB
testcase_06 AC 56 ms
54,068 KB
testcase_07 AC 57 ms
54,100 KB
testcase_08 AC 58 ms
54,112 KB
testcase_09 AC 56 ms
54,104 KB
testcase_10 AC 60 ms
54,040 KB
testcase_11 AC 55 ms
52,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

// 処理
class Process {
    private PrintWriter printWriter;
    private int L;
    private int M;
    private int N;

    Process(PrintWriter printWriter, int L, int M, int N) {
        this.printWriter = printWriter;
        this.L = L;
        this.M = M;
        this.N = N;
    }

    // 結果を出力
    void printResult() throws IOException {
        int numOf1000YenBills = 0;

        int exchangeCount = 0;

        // 1 円硬貨を 25 円硬貨に両替
        exchangeCount = N / 25;
        N -= 25 * exchangeCount;
        M += exchangeCount;

        // 25 円硬貨を 100 円硬貨に両替
        exchangeCount = M / 4;
        M -= 4 * exchangeCount;
        L += exchangeCount;

        // 100 円硬貨を 1000 円札に両替
        exchangeCount = L / 10;
        L -= 10 * exchangeCount;
        numOf1000YenBills += exchangeCount;

        printWriter.println(L + M + N);
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        var bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        var printWriter    = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // 入力
        int L = Integer.parseInt(bufferedReader.readLine().trim());

        int M = Integer.parseInt(bufferedReader.readLine().trim());

        int N = Integer.parseInt(bufferedReader.readLine().trim());

        // Process クラスで処理を行う
        var process = new Process(printWriter, L, M, N);
        process.printResult();

        // 各ストリームを閉じる
        // 出力ストリームを閉じるときに標準出力に文字を出力する
        bufferedReader.close();
        printWriter.close();
    }
}
0