結果

問題 No.355 数当てゲーム(2)
ユーザー TatsuDXTatsuDX
提出日時 2016-10-16 20:50:16
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 3,056 bytes
コンパイル時間 3,654 ms
コンパイル使用メモリ 80,848 KB
実行使用メモリ 75,404 KB
平均クエリ数 1.00
最終ジャッジ日時 2023-09-23 11:36:01
合計ジャッジ時間 22,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Test {
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int idx = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (i == j)
					continue;
				for (int k = 0; k < 4; k++) {
					if (i == k)
						continue;
					if (j == k)
						continue;
					for (int l = 0; l < 4; l++) {
						if (i == l)
							continue;
						if (j == l)
							continue;
						if (k == l)
							continue;
						p[idx][0] = i;
						p[idx][1] = j;
						p[idx][2] = k;
						p[idx][3] = l;
						idx++;
					}
				}
			}
		}
		chk();
	}

	public static int[] b = new int[4];
	public static int[] c = new int[4];
	public static boolean[] t = new boolean[10];
	public static int[][] p = new int[24][4];

	public static void chk() {
		int hit, blw;
		for (b[0] = 0; b[0] < 7; b[0]++) {
			for (b[1] = b[0] + 1; b[1] < 8; b[1]++) {
				for (b[2] = b[1] + 1; b[2] < 9; b[2]++) {
					for (b[3] = b[2] + 1; b[3] < 10; b[3]++) {
						System.out.println("" + b[0] + b[1] + b[2] + b[3]);
						hit = sc.nextInt();
						blw = sc.nextInt();
						if (hit == 4) {
							return;
						} else if (hit + blw == 4) {
							chk4();
							return;
						} else if (hit + blw == 3) {
							Arrays.fill(t, false);
							chk3();
							return;
						} else if (hit + blw == 0) {
							Arrays.fill(t, false);
							chk0();
							return;
						}
					}
				}
			}
		}
	}

	public static void chk0() {
		int hit, blw;
		for (int i = 0; i < 4; i++) {
			c[i] = b[i];
			t[b[i]] = true;
		}
		for (b[0] = c[0] + 1; b[0] < 7; b[0]++) {
			if (t[b[0]])
				continue;
			for (b[1] = b[0] + 1; b[1] < 8; b[1]++) {
				if (t[b[1]])
					continue;
				for (b[2] = b[1] + 1; b[2] < 9; b[2]++) {
					if (t[b[2]])
						continue;
					for (b[3] = b[2] + 1; b[3] < 10; b[3]++) {
						if (t[b[3]])
							continue;
						System.out.println("" + b[0] + b[1] + b[2] + b[3]);
						hit = sc.nextInt();
						blw = sc.nextInt();
						if (hit == 4) {
							return;
						} else if (hit + blw == 4) {
							chk4();
							return;
						} else if (hit + blw == 3) {
							chk3();
							return;
						}
					}
				}
			}
		}
	}

	public static void chk3() {
		int hit, blw;
		for (int i = 0; i < 4; i++) {
			c[i] = b[i];
			t[c[i]] = true;
		}
		for (int i = 0; i < 4; i++) {
			for (int j = c[i] + 1; j < 10; j++) {
				if (t[j])
					continue;
				b[i] = j;
				System.out.println("" + b[0] + b[1] + b[2] + b[3]);
				hit = sc.nextInt();
				blw = sc.nextInt();
				if (hit == 4) {
					return;
				} else if (hit + blw == 4) {
					chk4();
					return;
				} else if (hit + blw == 2) {
					break;
				}
			}
			b[i] = c[i];
		}
	}

	public static void chk4() {
		int hit, blw;
		for (int i = 0; i < 4; i++) {
			c[i] = b[i];
		}
		for (int i = 1; i < 24; i++) {
			for (int j = 0; j < 4; j++) {
				b[j] = c[p[i][j]];
			}
			System.out.println("" + b[0] + b[1] + b[2] + b[3]);
			hit = sc.nextInt();
			blw = sc.nextInt();
			if (hit == 4) {
				return;
			}
		}
	}
}
0