結果

問題 No.24 数当てゲーム
ユーザー l1267976l1267976
提出日時 2017-03-08 17:14:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 1,449 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 75,064 KB
実行使用メモリ 56,504 KB
最終ジャッジ日時 2023-09-06 00:04:43
合計ジャッジ時間 3,793 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
56,136 KB
testcase_01 AC 116 ms
55,768 KB
testcase_02 AC 108 ms
55,840 KB
testcase_03 AC 111 ms
55,792 KB
testcase_04 AC 113 ms
55,924 KB
testcase_05 AC 116 ms
56,368 KB
testcase_06 AC 109 ms
56,132 KB
testcase_07 AC 112 ms
56,400 KB
testcase_08 AC 111 ms
56,080 KB
testcase_09 AC 108 ms
56,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            map.put(i, 0);
        }

        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int n = Integer.parseInt(str);

        for (int i = 0; i < n; i++) {
            String[] strs = sc.nextLine().split(" ");

            int a[] = new int[4];
            for (int j = 0; j < a.length; j++) {
                a[j] = Integer.parseInt(strs[j]);
            }

            String r = strs[4];

            if (r.equals("NO")) {
                for (int j = 0; j < a.length; j++) {
                    if (map.containsKey(a[j])) {
                        map.remove(a[j]);
                    }
                }
            } else {
                for (int j = 0; j < a.length; j++) {
                    if (map.containsKey(a[j])) {
                        map.put(a[j], map.get(a[j]) + 1);
                    }
                }
            }
        }

        int maxCnt = -1;
        int maxNo = -1;

        for (Map.Entry<Integer, Integer> e : map.entrySet()) {
            if (e.getValue() > maxCnt) {
                maxCnt = e.getValue();
                maxNo = e.getKey();
            }
        }

        System.out.println(maxNo);

        sc.close();
    }

}
0