Advertisement
haufont

Untitled

Aug 28th, 2016
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include<iostream>
  2. #include<set>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<set>
  6. #include<vector>
  7. #include<string>
  8. #include<stdlib.h>
  9. #include<math.h>
  10. #include<stdio.h>
  11. using namespace std;
  12. int main()
  13. {
  14. int q[4][4];
  15. char a;
  16. int xs, zs, h;
  17. xs = zs = h = 0;
  18. bool ansx = false, ansz = false;
  19. for (int i = 1; i <= 3; i++)
  20. {
  21. for (int j = 1; j <= 3; j++)
  22. {
  23. cin >> a;
  24. if (a == 'X')
  25. {
  26. xs++;
  27. q[i][j] = 1;
  28. }
  29. if (a == '0')
  30. {
  31. zs++;
  32. q[i][j] = -1;
  33. }
  34. if (a == '.')
  35. {
  36. q[i][j] = 0;
  37. }
  38. }
  39. }
  40. for (int i = 1; i < 4; i++)
  41. {
  42. int rt = 7;
  43. if (q[i][1] + q[i][2] + q[i][3] == 3)
  44. ansx = true;
  45. if (q[1][i] + q[2][i] + q[3][i] == 3)
  46. ansx = true;
  47. if (q[i][1] + q[i][2] + q[i][3] == -3)
  48. ansz = true;
  49. if (q[1][i] + q[2][i] + q[3][i] == -3)
  50. ansz = true;
  51. }
  52. if (q[1][3] + q[2][2] + q[3][1] == 3)
  53. {
  54. ansx = true;
  55. h++;
  56. }
  57. if (q[1][1] + q[2][2] + q[3][3] == 3)
  58. {
  59. ansx = true;
  60. h++;
  61. }
  62. if (q[1][3] + q[2][2] + q[3][1] == -3)
  63. {
  64. ansz = true;
  65. }
  66. if (q[1][1] + q[2][2] + q[3][3] == -3)
  67. {
  68. ansz = true;
  69. }
  70. if (((xs - zs) > 1) || (zs > xs) || (ansx && ansz))
  71. {
  72. cout << "illegal";
  73. return 0;
  74. }
  75. if (zs + xs == 9)
  76. {
  77. if (!ansz && !ansx)
  78. {
  79. cout << "draw" << endl;
  80. return 0;
  81. }
  82. else
  83. {
  84. if ((ansx) && (!ansz))
  85. {
  86. cout << "the first player won" << endl;
  87. return 0;
  88. }
  89. else
  90. {
  91. if ((ansz) && (!ansx))
  92. {
  93. cout << "the second player won" << endl;
  94. return 0;
  95. }
  96. else
  97. {
  98. cout << "illegal" << endl;
  99. return 0;
  100. }
  101. }
  102. }
  103. }
  104. else
  105. {
  106. if (xs + zs < 9)
  107. {
  108. if (!ansx && !ansz)
  109. {
  110. if (xs == zs)
  111. {
  112. cout << "first" << endl;
  113. return 0;
  114. }
  115. else
  116. {
  117. if (xs == zs + 1)
  118. {
  119. cout << "second" << endl;
  120. return 0;
  121. }
  122. else
  123. {
  124. cout << "illegal" << endl;
  125. return 0;
  126. }
  127. }
  128. }
  129. else
  130. {
  131. if ((ansx) && (!ansz))
  132. {
  133. cout << "the first player won" << endl;
  134. return 0;
  135. }
  136. else
  137. {
  138. if ((ansz) && (!ansx))
  139. {
  140. cout << "the second player won" << endl;
  141. return 0;
  142. }
  143. else
  144. {
  145. cout << "illegal" << endl;
  146. return 0;
  147. }
  148. }
  149. }
  150. }
  151. else
  152. {
  153. cout << "illegal" << endl;
  154. return 0;
  155. }
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement