Yesver08

Bermain Tic Tac Toe

Feb 15th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. string winner = "";
  9.  
  10. void cek(char c) {
  11.     if (c == 'O') winner = "Aneb";
  12.     else if (c == 'X') winner = "Amar";
  13. }
  14. int main() {
  15.     char c[3][3];
  16.     bool isFull = true;
  17.     for (int i = 0; i < 3; i++) {
  18.         for (int j = 0; j < 3; j++) {
  19.             cin >> c[i][j];
  20.             if (c[i][j] == '*') isFull = false;
  21.         }
  22.     }
  23.     for (int i = 0; i < 3; i++) {
  24.         if (c[i][0] == c[i][1] && c[i][1] == c[i][2]) {
  25.             cek(c[i][0]);
  26.         }
  27.         if (c[0][i] == c[1][i] && c[1][i] == c[2][i]) {
  28.             cek(c[0][i]);
  29.         }
  30.     }
  31.     if (c[0][0] == c[1][1] && c[1][1] == c[2][2]) {
  32.         cek(c[1][1]);
  33.     }
  34.     if (c[2][0] == c[1][1] && c[1][1] == c[0][2]) {
  35.         cek(c[1][1]);
  36.     }
  37.     if (winner != "") cout << winner << " Menang";
  38.     else {
  39.         if (isFull) cout << "Seri";
  40.         else cout << "Permainan Belum Selesai";
  41.     }
  42. }
  43.  
Add Comment
Please, Sign In to add comment