using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; this.FirstStep(); } private bool FirstStep(){ Console.WriteLine("1 2 3 4"); int[] ret1 = GetInput(); if(ret1[0] == 4) { return true; } else if(ret1.Sum() == 4) { this.InList.AddRange(new int[]{1,2,3,4}); return ProcLast4(); } else if(ret1.Sum() == 0) { this.OutList.AddRange(new int[]{1,2,3,4}); return this.ProcOut3(); } else if(ret1.Sum() == 1) { return this.ProcIn1_Out3(new int[]{1,2,3,4}); } else if(ret1.Sum() == 3) { return this.ProcIn3_Out1(new int[]{1,2,3,4}); } Console.WriteLine("5 6 7 8"); int[] ret2 = GetInput(); if(ret2[0] == 4) { return true; } else if(ret2.Sum() == 4) { this.InList.AddRange(new int[]{5,6,7,8}); return ProcLast4(); } else if(ret2.Sum() == 0) { this.OutList.AddRange(new int[]{5,6,7,8}); return this.ProcOut3(); } else if(ret2.Sum() == 1) { return this.ProcIn1_Out3(new int[]{5,6,7,8}); } else if(ret2.Sum() == 3) { return this.ProcIn3_Out1(new int[]{5,6,7,8}); } Console.WriteLine("9 0 1 2"); int[] ret3 = GetInput(); if(ret3[0] == 4) { return true; } else if(ret3.Sum() == 4) { this.InList.AddRange(new int[]{9,0,1,2}); return ProcLast4(); } else if(ret3.Sum() == 0) { this.OutList.AddRange(new int[]{9,0,1,2}); return this.ProcOut3(); } else if(ret3.Sum() == 1) { return this.ProcIn1_Out3(new int[]{9,0,1,2}); } else if(ret3.Sum() == 3) { return this.ProcIn3_Out1(new int[]{9,0,1,2}); } List ng = new List(new int[]{9,0, 3, 4}); this.OutList.AddRange(ng); return this.ProcOut3(); } private bool ProcIn3_Out1(int[] target) { List otherList = new List(BaseNumList.Where(a=>!target.Contains(a)).Take(2)); foreach (int item in target) { int min = int.MaxValue; foreach (int hikaku in otherList) { List subList = new List(target); subList.Remove(item); subList.Add(hikaku); Console.WriteLine(string.Join(" ", subList)); int[] ret = GetInput(); if(ret[0] == 4) { return true; } if(ret.Sum() == 4) { this.InList.Clear(); this.InList.AddRange(subList); return this.ProcLast4(); } min = Math.Min(min, ret.Sum()); } if(min == 3) { this.InList.Clear(); this.InList.AddRange(target); this.InList.Remove(item); return this.ProcIn3(); } } return true; } private bool ProcIn3() { List target = new List(BaseNumList.Where(a=>!InList.Contains(a))); foreach (int item in target) { List temp = new List(InList.Take(3)); temp.Add(item); Console.WriteLine(string.Join(" ", temp)); int[] ret = GetInput(); if(ret[0] == 4) { return true; } if(ret.Sum() == 4) { InList.Add(item); return this.ProcLast4(); } } return true; } private bool ProcIn1_Out3(int[] target) { List hikaku = new List(BaseNumList.Where(a=>!target.ToList().Contains(a)).Take(4)); for(int i=0; i tmp = new List(target); tmp.RemoveAt(i); tmp.Add(hikaku[j]); Console.WriteLine(string.Join(" ", tmp)); int[] ret = GetInput(); maxVal = Math.Min(maxVal, ret.Sum()); } if(maxVal == 0) { this.OutList.Clear(); this.OutList.AddRange(target); this.OutList.RemoveAt(i); return this.ProcOut3(); } } return true; } private bool ProcOut3() { List target = new List(BaseNumList.Where(a=>!OutList.Contains(a))); foreach (int num in target) { List tmp = new List(this.OutList.Take(3)); tmp.Add(num); Console.WriteLine(string.Join(" ", tmp)); int[] ret = GetInput(); if(ret.Sum() > 0) { if(!InList.Contains(num)) { InList.Add(num); if(InList.Count == 4) { return ProcLast4(); } } } } return true; } /// 入力候補4つが確定している private bool ProcLast4() { OutList.Clear(); OutList.AddRange(BaseNumList); InList.ForEach(a=>OutList.Remove(a)); int[] ans = new int[4]; for(int i=0; i tmp = new List(); tmp.AddRange(OutList.Take(3)); tmp.Insert(j, InList[i]); Console.WriteLine(string.Join(" ", tmp)); int[] ret = this.GetInput(); if(ret[0] == 1) { ans[j] = InList[i]; break; } } } Console.WriteLine(string.Join(" ", ans)); return true; } private int[] GetInput() { return Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); } private List OutList = new List(); private List InList = new List(); private int[] BaseNumList = new int[]{0,1,2,3,4,5,6,7,8,9}; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 3 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }