Advertisement
haufont

Untitled

Aug 28th, 2016
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4. int A[4][4];
  5. int main()
  6. {
  7. char t;
  8. int x = 0;
  9. int y = 0;
  10. bool ty = false;
  11. for (int i = 1; i <= 3; i++)
  12. {
  13. for (int v = 1; v <= 3; v++)
  14. {
  15. cin >> t;
  16. if (t == '.')
  17. {
  18. ty = true;
  19. A[i][v] = 0;
  20. }
  21. if (t == 'X')
  22. {
  23. x++;
  24. A[i][v] = 1;
  25.  
  26. }
  27. if (t == '0')
  28. {
  29. y++;
  30. A[i][v] = -1;
  31. }
  32. }
  33. }
  34. bool r1 = false;
  35. bool r2 = false;
  36. if (((x - y) > 1) || (y > x))
  37. {
  38. cout << "illegal";
  39. return 0;
  40. }
  41. for (int i = 1; i <= 3; i++)
  42. {
  43. if (A[i][1] + A[i][2] + A[i][3] == 3)
  44. {
  45. r1 = true;
  46. }
  47. if (A[i][1] + A[i][2] + A[i][3] == -3)
  48. {
  49. r2 = true;
  50. }
  51. }
  52. for (int i = 1; i <= 3; i++)
  53. {
  54. if (A[1][i] + A[2][i] + A[3][i] == 3)
  55. {
  56. r1 = true;
  57. }
  58. if (A[1][i] + A[2][i] + A[3][i] == -3)
  59. {
  60. r2 = true;
  61. }
  62. }
  63. if (A[1][1] + A[2][2] + A[3][3] == 3)
  64. {
  65. r1 = true;
  66. }
  67. if (A[1][1] + A[2][2] + A[3][3] == -3)
  68. {
  69. r2 = true;
  70. }
  71. if (A[1][3] + A[2][2] + A[3][1] == 3)
  72. {
  73. r1 = true;
  74. }
  75. if (A[1][3] + A[2][2] + A[3][1] == -3)
  76. {
  77. r2 = true;
  78. }
  79. if (r1&&r2)
  80. {
  81. cout << "illegal";
  82. return 0;
  83. }
  84. if ((!r1 && !r2)&&(x+y==9))
  85. {
  86. cout << "draw";
  87. return 0;
  88. }
  89. if (r1)
  90. {
  91. if (y == x)
  92. {
  93. cout << "illegal";
  94. return 0;
  95. }
  96. cout << "the first player won";
  97. return 0;
  98. }
  99. if (r2)
  100. {
  101. if (x - y == 1)
  102. {
  103. cout << "illegal";
  104. return 0;
  105. }
  106. cout << "the second player won";
  107. return 0;
  108. }
  109. if (x > y)
  110. {
  111. cout << "second";
  112. return 0;
  113. }
  114. if (y == x)
  115. {
  116. cout << "first";
  117. return 0;
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement