Advertisement
haufont

Untitled

Aug 25th, 2016
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 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, ansx, ansz;
  17. xs = zs = ansx = ansz = 0;
  18. for (int i = 1; i <= 3; i++)
  19. {
  20. for (int j = 1; j <= 3; j++)
  21. {
  22. cin >> a;
  23. if (a == 'X')
  24. {
  25. xs++;
  26. q[i][j] = 1;
  27. }
  28. if (a == '0')
  29. {
  30. zs++;
  31. q[i][j] = -1;
  32. }
  33. if (a == '.')
  34. {
  35. q[i][j] = 0;
  36. }
  37. }
  38. }
  39. for (int i = 1; i < 4; i++)
  40. {
  41. if (q[i][1] + q[i][2] + q[i][3] == 3)
  42. ansx++;
  43. if (q[1][i] + q[2][i] + q[3][i] == 3)
  44. ansx++;
  45. if (q[i][1] + q[i][2] + q[i][3] == -3)
  46. ansz++;
  47. if (q[1][i] + q[2][i] + q[3][i] == -3)
  48. ansz++;
  49. }
  50. if (q[1][3] + q[2][2] + q[3][1] == 3)
  51. ansx++;
  52. if (q[1][1] + q[2][2] + q[3][3] == 3)
  53. ansx++;
  54. if (q[1][3] + q[2][2] + q[3][1] == -3)
  55. ansz++;
  56. if (q[1][1] + q[2][2] + q[3][3] == -3)
  57. ansz++;
  58. if (zs > xs || xs - 1 > zs || ansx + ansz > 1)
  59. {
  60. cout << "illegal" << endl;
  61. return 0;
  62. }
  63. if (xs + zs < 9)
  64. {
  65. if (!(ansx + ansz))
  66. {
  67. if (xs == zs + 1)
  68. {
  69. cout << "second" << endl;
  70. return 0;
  71. }
  72. if (xs == zs)
  73. {
  74. cout << "first" << endl;
  75. return 0;
  76. }
  77. }
  78. if (ansx == 1 && !ansz)
  79. {
  80. cout << "the first player won" << endl;
  81. return 0;
  82. }
  83. if (ansz == 1 && !ansx)
  84. {
  85. cout << "the second player won" << endl;
  86. return 0;
  87. }
  88. }
  89. else
  90. {
  91. if (!(ansx + ansz))
  92. {
  93. cout << "draw" << endl;
  94. return 0;
  95. }
  96. if (ansx == 1 && !ansz)
  97. {
  98. cout << "the first player won" << endl;
  99. return 0;
  100. }
  101. if (ansz == 1 && !ansx)
  102. {
  103. cout << "the second player won" << endl;
  104. return 0;
  105. }
  106. }
  107. cout << "illegal" << endl;
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement