package no355; import java.util.Arrays; import java.util.Scanner; public class Main { static int[] query = new int[4]; static int hit = 0; static int blow = 0; static Scanner sc = new Scanner(System.in); public static void main(String[] args) { for(int i=0;i<4;i++) { query[i] = i; } query(); for(int i=0;i<4;i++) { int best = -1; int bestj = -1; for(int j=0;j<=9;j++) { query[i] = j; if (!isValid()) continue; query(); if (hit + blow > best) { best = hit + blow; bestj = j; } } query[i] = bestj; } Arrays.sort(query); do { query(); }while(nextPermutation(query)); } public static boolean isValid() { boolean[] used = new boolean[10]; for(int i=0;i<4;i++) { int x = query[i]; if (used[x]) { return false; } used[x] = true; } return true; } public static void query() { StringBuilder sb = new StringBuilder(); for(int i=0;i<4;i++) { if (i > 0) sb.append(' '); sb.append(query[i]); } System.out.println(sb.toString()); hit = sc.nextInt(); blow = sc.nextInt(); if (hit == 4) { System.exit(0); } } static boolean nextPermutation(int[] p) { for(int a=p.length-2;a>=0;--a) { if(p[a]
p[a]) { int t = p[a]; p[a] = p[b]; p[b] = t; for(++a, b=p.length-1;a