Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll              long long
  4. #define pb              push_back
  5. #define mp              make_pair
  6. #define X               first
  7. #define Y               second
  8. #define forn( i, n )    for( ll i = 0; i < (ll) (n); i ++ )
  9. #define endl            '\n'
  10.  
  11. using namespace std;
  12.  
  13. string s[3];
  14. ll x, o, X, O;
  15. vector< pair< ll, ll > > v;
  16.  
  17. bool check( char a ) {
  18.     forn( i, 3 ) {
  19.         if( s[i][0] == a && s[i][1] == a && s[i][2] == a )
  20.             return true;
  21.         if( s[0][i] == a && s[1][i] == a && s[2][i] == a )
  22.             return true;
  23.     }
  24.     if( s[0][0] == a && s[1][1] == a && s[2][2] == a )
  25.         return true;
  26.     if( s[0][2] == a && s[1][1] == a && s[2][0] == a )
  27.         return true;
  28.     return false;
  29. }
  30.  
  31. void win() {
  32.     if( check( 'x' ) )
  33.         X ++;
  34.     if( check( 'o' ) )
  35.         O ++;
  36. }
  37.  
  38. int main( void ) {
  39.     forn( i, 3 ) {
  40.         cin >> s[i];
  41.         forn( j, 3 ) {
  42.             if( s[i][j] == 'x' )
  43.                 x ++;
  44.             else if( s[i][j] == 'o' )
  45.                 o ++;
  46.             else
  47.                 v.pb( mp( i, j ) );
  48.         }
  49.     }
  50.     if( check( 'x' ) && check( 'o' ) )
  51.         return cout << "tie" << endl, 0;
  52.     if( check( 'x' ) )
  53.         return cout << 'x' << endl, 0;
  54.     if( check( 'o' ) )
  55.         return cout << 'o' << endl, 0;
  56.        
  57.        
  58.     s[v[0].X][v[0].Y] = ( x > o ? 'o' : 'x' );
  59.     win();
  60.     if( !check( 'x' ) && !check( 'o' ) ) {
  61.         s[v[1].X][v[1].Y] = ( x < o ? 'o' : 'x' );
  62.         win();
  63.         s[v[1].X][v[1].Y] = '.';
  64.     }  
  65.     s[v[0].X][v[0].Y] = '.';
  66.    
  67.    
  68.     s[v[1].X][v[1].Y] = ( x > o ? 'o' : 'x' );
  69.     win();
  70.     if( !check( 'x' ) && !check( 'o' ) ) {
  71.         s[v[0].X][v[0].Y] = ( x < o ? 'o' : 'x' );
  72.         win();
  73.         s[v[0].X][v[0].Y] = '.';
  74.     }  
  75.     s[v[1].X][v[1].Y] = '.';
  76.    
  77.     if( X == O )
  78.         cout << "tie" << endl;
  79.     else if( X > O )
  80.         cout << 'x' << endl;
  81.     else
  82.         cout << 'o' << endl;
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement