Skip to main content

All Solution Code of CodeChef May Long Challenge 2021

competitve programming solution here...

solution code of Tic Tac Toe problem number-4 of may long challenge codechef

 Tic Tac Toe Problem Solution Code:  CodeChef

Solution Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll cx = 0, co =0, c_= 0;
        char a[3][3];
        for(ll i=0;i<3;i++)
        {
            for(ll j=0;j<3;j++)
            {
                cin>>a[i][j];
                if(a[i][j]=='X')cx++;
                if(a[i][j]=='O')co++;
                if(a[i][j]=='_')c_++;
            }
        }
        ll wx = 0, wo = 0;
        if(a[0][0== 'X' && a[1][0== 'X' && a[2][0== 'X')wx=1;
        if(a[0][1== 'X' && a[1][1== 'X' && a[2][1== 'X')wx=1;
        if(a[0][2== 'X' && a[1][2== 'X' && a[2][2== 'X')wx=1;
        if(a[0][0== 'X' && a[1][1== 'X' && a[2][2== 'X')wx=1;
        if(a[0][0== 'X' && a[0][1== 'X' && a[0][2== 'X')wx=1;
        if(a[1][0== 'X' && a[1][1== 'X' && a[1][2== 'X')wx=1;
        if(a[2][0== 'X' && a[2][1== 'X' && a[2][2== 'X')wx=1;
        if(a[0][2== 'X' && a[1][1== 'X' && a[2][0== 'X')wx=1;
        
        if(a[0][0== 'O' && a[1][0== 'O' && a[2][0== 'O')wo=1;
        if(a[0][1== 'O' && a[1][1== 'O' && a[2][1== 'O')wo=1;
        if(a[0][2== 'O' && a[1][2== 'O' && a[2][2== 'O')wo=1;
        if(a[0][0== 'O' && a[1][1== 'O' && a[2][2== 'O')wo=1;
        if(a[0][0== 'O' && a[0][1== 'O' && a[0][2== 'O')wo=1;
        if(a[1][0== 'O' && a[1][1== 'O' && a[1][2== 'O')wo=1;
        if(a[2][0== 'O' && a[2][1== 'O' && a[2][2== 'O')wo=1;
        if(a[0][2== 'O' && a[1][1== 'O' && a[2][0== 'O')wo=1;

        if((wx == 1 && wo == 1|| ((cx-co)<0|| (cx-co)>1)cout<<3<<"\n";
        else if(cx == 0 && co == 0 && c_ == 9)cout<<2<<"\n";
        else if(wx == 1 && wo == 0 && cx > co)cout<<1<<"\n";
        else if(wx == 0 && wo == 1 && cx == co)cout<<1<<"\n";
        else if(wx == 0 && wo == 0 && c_ == 0)cout<<1<<"\n";
        else if(wx == 0 && wo == 0 && c_ > 0)cout<<2<<"\n";
        else cout<<3<<"\n";
    }
    return 0;
}

Comments

Popular posts from this blog

solution code of Valid Paths problem number-7 of may long challenge codechef

 Valid Paths Problem Solution Code: CodeChef Solution Code #include <bits/stdc++.h> using   namespace   std ; #define   ll   long   long #define   f ( i ,  a ,  b )  for ( int  i = a; i < b; i ++ ) #define   mod   1000000007 #define   mk   make_pair #define   uniq ( v ) (v). erase ( unique ( all (v)), (v). end ()) #define   ff  first #define   ss  second #define   rf ( i ,  a ,  b )  for ( int  i = a;i >= b;i -- ) #define   sc ( a )  scanf ( " %lld " ,  & a) #define   pf   printf #define   sz ( a ) ( int )(a. size ()) #define   psf  push_front #define   ppf  pop_front #define   ppb  pop_back #define   pb  push_back #define   pq  priority_queue #define   all ( s ) s. begin (),s. end () #define   sp ( a )  setprecision (a)...

solution code of An Interesting Sequence problem number-8 of may long challenge codechef

An Interesting Sequence Problem Solution Code: CodeChef #include   <bits/stdc++.h> using   namespace   std ; #define   endl   " \n " int   main () {     cin. tie ( 0 );      int  N  =   4 e 6   +   5 ;      int  phi[N], ans[N];      for  ( int  i  =   0 ; i  <  N; i ++ )     {         phi[i]  =  i;         ans[i]  =   0 ;     }      for  ( int  p  =   2 ; p  <  N; p ++ )     {          if  (phi[p]  ==  p)         {            ...

solution code of Tree House problem number-6 of may long challenge codechef

 Tree House Problem Solution Code: CodeChef Solution Code #pragma   GCC   optimize (" Ofast ", " unroll-loops ") #include   <bits/stdc++.h> using   namespace   std ; #define   int   long   long   int #define   double   long   double using   pii   =   pair < int ,  int >; template  < typename   T > using   Prior   =   std :: priority_queue < T ,  vector < T >,  greater < T >>; #define   X  first #define   Y  second #define   eb  emplace_back #define   ALL ( x )  begin (x),  end (x) #define   RALL ( x )  rbegin (x),  rend (x) #define   fastIO ()  ios_base ::sync_with_stdio, cin. tie ( 0 ) mt19937_64  rng( chrono :: steady_clock :: now (). time_since_epoch (). count ()); inline   int   getRand ( int   L ,  int   R ) { ...