SHARE
    TWEET
    nq1s788

    крестики нолики

    Apr 12th, 2025
    658
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    C++ 1.87 KB | None | 0 0
    1. #include <iostream>
    2. #include <set>
    3. #include <vector>
    4. #include <deque>
    5. #define se second
    6. #define fi first
    7. #define mp make_pair
    8. #define pb push_back
    9. using namespace std;
    10. char step(vector<vector<char>> field, char turn, int left) {
    11. bool f = false;
    12. for (int i = 0; i < 3; i++) {
    13. if ((field[0][i] == field[1][i]) && (field[1][i] == field[2][i]) && (field[1][i] != '#')) f = true;
    14. if ((field[i][0] == field[i][1]) && (field[i][1] == field[i][2]) && (field[i][1] != '#')) f = true;
    15. }
    16. if ((field[0][0] == field[1][1]) && (field[1][1] == field[2][2]) && (field[0][0] != '#')) f = true;
    17. if ((field[0][2] == field[1][1]) && (field[1][1] == field[2][0]) && (field[0][2] != '#')) f = true;
    18. if (f) return 'l';
    19. if (left == 0) return 'd';
    20. bool w_flag = false;
    21. bool d_flag = false;
    22. bool l_flag = false;
    23. for (int i = 0; i < 3; i++) {
    24. for (int j = 0; j < 3; j++) {
    25. if (field[i][j] == '#') {
    26. field[i][j] = turn;
    27. char res;
    28. if (turn == 'X') {
    29. res = step(field, 'O', left - 1);
    30. } else {
    31. res = step(field, 'X', left - 1);
    32. }
    33. field[i][j] = '#';
    34. if (res == 'w') w_flag = true;
    35. else if (res == 'd') d_flag = true;
    36. else l_flag = true;
    37. }
    38. }
    39. }
    40. if (l_flag) return 'w';
    41. if (d_flag) return 'd';
    42. return 'l';
    43. }
    44. int main() {
    45. vector<vector<char>> field(3, vector<char>(3));
    46. for (vector<char>& e : field) {
    47. string s;
    48. cin >> s;
    49. e[0] = s[0];
    50. e[1] = s[1];
    51. e[2] = s[2];
    52. }
    53. char res = step(field, 'X', 3);
    54. if (res == 'w') cout << "Crosses win";
    55. else if (res == 'd') cout << "Draw";
    56. else cout << "Ouths win";
    57. return 0;
    58. }
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /