結果

問題 No.24 数当てゲーム
ユーザー eagleeagle
提出日時 2022-06-15 13:46:35
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,811 bytes
コンパイル時間 3,398 ms
コンパイル使用メモリ 75,176 KB
実行使用メモリ 55,960 KB
最終ジャッジ日時 2023-07-27 09:26:09
合計ジャッジ時間 6,340 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,360 KB
testcase_01 AC 127 ms
55,292 KB
testcase_02 AC 132 ms
55,704 KB
testcase_03 WA -
testcase_04 AC 131 ms
55,604 KB
testcase_05 AC 132 ms
55,588 KB
testcase_06 AC 132 ms
55,840 KB
testcase_07 AC 135 ms
55,580 KB
testcase_08 AC 132 ms
55,444 KB
testcase_09 AC 132 ms
55,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//ターン数
		int N = sc.nextInt();
		ArrayList<Integer> yes = new ArrayList<>();
		ArrayList<Integer> no = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			//思い浮かべた数字
			int A = sc.nextInt();
			int B = sc.nextInt();
			int C = sc.nextInt();
			int D = sc.nextInt();
			//答えの数字の有無
			String R = sc.next();
			if(R.equals("NO")) {
				//答えでないことが確定する
				no.add(A);
				no.add(B);
				no.add(C);
				no.add(D);
			} else {
				//答え候補
				yes.add(A);
				yes.add(B);
				yes.add(C);
				yes.add(D);
			}
		}
		int[] num = new int[10];
		int cnt = 0;
		//答えでない数字をマークする
		for(int i = 0; i < no.size(); i++) {
			int n = no.get(i);
			if(num[n] == 0) {
				num[n] = -1;
				cnt++;
			}
		}
		int ans = 0;
		//答えが見つかる状況
		if(cnt == 9) {
			for(int i = 0; i < num.length; i++) {
				if(num[i] == 0) {
					ans = i;
					break;
				}
			}
		} else {
			boolean flg = false;
			//yesと答えられた数字から答え候補を取り出す
			for(int i = 0; i < yes.size(); i++) {
				int n = yes.get(i);
				if(num[n] == -1) {
					continue;
				}
				//数字が重複しているか
				for(int j = 0; j < yes.size(); j++) {
					if(i == j) {
						continue;
					}
					int nn = yes.get(j);
					if(n == nn) {
						ans = nn;
						flg = true;
						break;
					}
				}
				if(flg) {
					break;
				} else {
					num[n] = 1;
				}
			}
			if(!flg) {
				//最後の答えの求め方
				for(int i = 0; i < num.length; i++) {
					if(num[i] == 1) {
						ans = i;
					}
				}
			}
		}
		System.out.println(ans);
	}
}
0