Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define mp make_pair
- #define X first
- #define Y second
- #define forn( i, n ) for( ll i = 0; i < (ll) (n); i ++ )
- #define endl '\n'
- using namespace std;
- string s[3];
- ll x, o, X, O;
- vector< pair< ll, ll > > v;
- bool check( char a ) {
- forn( i, 3 ) {
- if( s[i][0] == a && s[i][1] == a && s[i][2] == a )
- return true;
- if( s[0][i] == a && s[1][i] == a && s[2][i] == a )
- return true;
- }
- if( s[0][0] == a && s[1][1] == a && s[2][2] == a )
- return true;
- if( s[0][2] == a && s[1][1] == a && s[2][0] == a )
- return true;
- return false;
- }
- void win() {
- if( check( 'x' ) )
- X ++;
- if( check( 'o' ) )
- O ++;
- }
- int main( void ) {
- forn( i, 3 ) {
- cin >> s[i];
- forn( j, 3 ) {
- if( s[i][j] == 'x' )
- x ++;
- else if( s[i][j] == 'o' )
- o ++;
- else
- v.pb( mp( i, j ) );
- }
- }
- if( check( 'x' ) && check( 'o' ) )
- return cout << "tie" << endl, 0;
- if( check( 'x' ) )
- return cout << 'x' << endl, 0;
- if( check( 'o' ) )
- return cout << 'o' << endl, 0;
- s[v[0].X][v[0].Y] = ( x > o ? 'o' : 'x' );
- win();
- if( !check( 'x' ) && !check( 'o' ) ) {
- s[v[1].X][v[1].Y] = ( x < o ? 'o' : 'x' );
- win();
- s[v[1].X][v[1].Y] = '.';
- }
- s[v[0].X][v[0].Y] = '.';
- s[v[1].X][v[1].Y] = ( x > o ? 'o' : 'x' );
- win();
- if( !check( 'x' ) && !check( 'o' ) ) {
- s[v[0].X][v[0].Y] = ( x < o ? 'o' : 'x' );
- win();
- s[v[0].X][v[0].Y] = '.';
- }
- s[v[1].X][v[1].Y] = '.';
- if( X == O )
- cout << "tie" << endl;
- else if( X > O )
- cout << 'x' << endl;
- else
- cout << 'o' << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement