Advertisement
haufont

Untitled

Aug 25th, 2016
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 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 (xs + zs < 9)
  59. {
  60. if (!(ansx + ansz))
  61. {
  62. if (xs == zs + 1)
  63. {
  64. cout << "second" << endl;
  65. return 0;
  66. }
  67. if (xs == zs)
  68. {
  69. cout << "first" << endl;
  70. return 0;
  71. }
  72. }
  73. if (ansx == 1 && !ansz)
  74. {
  75. cout << "the first player won" << endl;
  76. return 0;
  77. }
  78. if (ansz == 1 && !ansx)
  79. {
  80. cout << "the second player won" << endl;
  81. return 0;
  82. }
  83. }
  84. else
  85. {
  86. if (!(ansx + ansz))
  87. {
  88. cout << "draw" << endl;
  89. return 0;
  90. }
  91. if (ansx == 1 && !ansz)
  92. {
  93. cout << "the first player won" << endl;
  94. return 0;
  95. }
  96. if (ansz == 1 && !ansx)
  97. {
  98. cout << "the second player won" << endl;
  99. return 0;
  100. }
  101. }
  102. cout << "illegal" << endl;
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement