fork(2) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication2
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. StreamReader sr = new StreamReader(Console.OpenStandardInput());
  15. StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
  16.  
  17. List<string[]> S = new List<string[]>();
  18. List<string[]> SPom = new List<string[]>();
  19. for (int k = 1; k < 7; k++)
  20. {
  21. for (int l = 1; l < 7; l++)
  22. {
  23. for (int m = 1; m < 7; m++)
  24. {
  25. for (int n = 1; n < 7; n++)
  26. {
  27. S.Add (new string[]{ k.ToString(),l.ToString(), m.ToString(), n.ToString() }) ;
  28. //SPom.Add(k + "" + l + "" + m + "" + n);
  29. }
  30. }
  31. }
  32. }
  33.  
  34. string[] guess = new string[] { "1","1","2","2"};
  35. for (int i = 0; i < guess.Length; i++)
  36. {
  37. Console.Write(guess[i]+" ");
  38.  
  39. }
  40. Console.WriteLine();
  41. //sw.WriteLine();
  42. //Console.Clear();
  43. //sw.Flush();
  44. string[] hint = sr.ReadLine().Split(' ');
  45. var asd = String.Join("",hint);
  46. int counter = 1;
  47. while (asd != "1111")
  48. {
  49. if (counter == 11)
  50. break;
  51. Array.Sort(hint);
  52. foreach (var combo in S)
  53. {
  54. if (!isEqual(Outcome(combo, guess), hint)) { }
  55. else
  56. SPom.Add(combo);
  57.  
  58. }
  59. S.Clear();
  60. foreach (var item in SPom)
  61. {
  62. S.Add(item);
  63. }
  64. guess = S[0];
  65. SPom.Clear();
  66. for (int i = 0; i < guess.Length; i++)
  67. {
  68. Console.Write(guess[i] + " ");
  69. }
  70. Console.WriteLine();
  71. //Console.Clear();
  72. //sw.WriteLine();
  73. //sw.Flush();
  74. hint = sr.ReadLine().Split(' ');
  75. asd = String.Join("", hint);
  76. counter++;
  77. }
  78. }
  79. static string[] Outcome(string[] combo,string[] guess)
  80. {
  81. //string[] outcome = new string[4];
  82. List<string> o = new List<string>();
  83. for (int i = 0; i < guess.Length; i++)
  84. {
  85. if (!hasElement(combo, guess[i]))
  86. {
  87. //outcome[i] = "-1";
  88. o.Add("-1");
  89. }
  90. else if (guess[i].Equals(combo[i]))
  91. {
  92. //outcome[i] = "1";
  93. o.Add("1");
  94. }
  95. else
  96. {
  97. //outcome[i] = "0";
  98. o.Add("0");
  99. }
  100. }
  101. //Array.Sort(outcome);
  102. o.Sort();
  103. return o.ToArray();
  104. }
  105. static bool isEqual(string[] tab1,string[] tab2)
  106. {
  107. for (int i = 0; i < tab2.Length; i++)
  108. {
  109. if (!(tab1[i].Equals(tab2[i])))
  110. {
  111. return false;
  112. }
  113. }
  114. return true;
  115. }
  116. static bool hasElement(string[] arr,string str)
  117. {
  118. for (int i = 0; i < arr.Length; i++)
  119. {
  120. if (arr[i].Equals(str))
  121. return true;
  122. }
  123. return false;
  124. }
  125. }
  126. }
  127.  
Success #stdin #stdout 0.03s 131648KB
stdin
1 1 -1 -1
1 1 1 0
1 1 1 -1
1 1 1 -1
1 1 1 -1
1 1 1 1
stdout
1 1 2 2 
1 1 1 1 
1 1 1 3 
1 1 1 4 
1 1 1 5 
1 1 1 6