Advertisement
STANAANDREY

hackathon: "tic tac toe binary"

Jan 24th, 2022 (edited)
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int board[3][3];
  4.  
  5. bool checkLine(int line) {
  6.     bool ok = false;
  7.     for (int col = 0; col < 3; col++) {
  8.         ok |= board[line][0] == board[line][1] && board[line][1] == board[line][2] && board[line][0];
  9.     }
  10.     return ok;
  11. }
  12.  
  13. bool checkCol(int col) {
  14.     bool ok = false;
  15.     for (int line = 0; line < 3; line++) {
  16.         ok |= board[0][col] == board[1][col] && board[1][col] == board[2][col] && board[0][col];
  17.     }
  18.     return ok;
  19. }
  20.  
  21. bool checkDiags() {
  22.     bool ok = false;
  23.     ok |= board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[1][1];
  24.     ok |= board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[1][1];
  25.     return ok;
  26. }
  27.  
  28. signed main() {
  29.     int n;
  30.     cin >> n;
  31.     for (int i = 0; i < n; i++) {
  32.         int val, x, y;
  33.         cin >> val >> x >> y;
  34.         board[x - 1][y - 1] = val + 1;
  35.     }
  36.     bool ok = false;
  37.     for (int line = 0; line < 3; line++) {
  38.         ok |= checkLine(line);
  39.     }
  40.     for (int col = 0; col < 3; col++) {
  41.         ok |= checkCol(col);
  42.     }
  43.     ok |= checkDiags();
  44.     cout << (ok ? "yes" : "no") << endl;
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement