結果

問題 No.24 数当てゲーム
ユーザー kitamoto0407kitamoto0407
提出日時 2024-03-08 05:03:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 1,996 bytes
コンパイル時間 8,549 ms
コンパイル使用メモリ 78,224 KB
実行使用メモリ 54,896 KB
最終ジャッジ日時 2024-03-08 05:04:11
合計ジャッジ時間 4,458 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
54,752 KB
testcase_01 AC 65 ms
54,856 KB
testcase_02 AC 64 ms
54,760 KB
testcase_03 AC 65 ms
54,872 KB
testcase_04 AC 64 ms
54,896 KB
testcase_05 AC 67 ms
54,872 KB
testcase_06 AC 65 ms
54,752 KB
testcase_07 AC 67 ms
54,880 KB
testcase_08 AC 66 ms
54,764 KB
testcase_09 AC 65 ms
54,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.stream.*;

// 処理
class Process {
    private PrintWriter printWriter;
    private int[][]  A;
    private String[] R;

    Process(PrintWriter printWriter, int[][] A, String[] R) {
        this.printWriter = printWriter;
        this.A = A;
        this.R = R;
    }

    // 結果を出力
    void printResult() throws IOException {
        int[] numCount = new int[10];

        for(int i = 0; i < A.length; i++) {
            for(int j = 0; j < A[i].length; j++) {
                numCount[A[i][j]] = R[i].equals("YES") ? (numCount[A[i][j]] + 1) : (numCount[A[i][j]] - 1);
            }
        }

        int max = IntStream.of(numCount).max().getAsInt();
        int index = 0;
        for(int i = 0; i < numCount.length; i++) {
            if(numCount[i] == max) {
                index = i;
                break;
            }
        }

        printWriter.println(index);
    }
}

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 N = Integer.parseInt(bufferedReader.readLine().trim());

        String[] input = new String[5];
        int[][] A = new int[N][4];
        String[] R = new String[N];
        for(int n = 0; n < N; n++) {
            input = bufferedReader.readLine().trim().split("[ ]+");
            for(int a = 0; a < A[n].length; a++) {
                A[n][a] = Integer.parseInt(input[a]);
            }
            R[n] = input[4];
        }

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

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