Try comparing it with my code , everyone has different style of implementing. Its hard to say where your code fails. You can also brute check at which case your code is failing, as there are only 3**9 cases
How do you prove that the encoding method used will be unique for all possible states?
hi,can you find the wrong case in my code?
the answers here are right in my code
Already have, unless you’ve updated your code since
The same testcase as this one:
can anyone tell. me why i am getting WA
#include <iostream>
using namespace std;
int wins(char board[][3],char ch)
{ int res=0;
if(board[0][0]==ch&&board[0][0]==board[0][1]&&board[0][1]==board[0][2])
res++;
if(board[0][0]==ch&&board[0][0]==board[1][0]&&board[1][0]==board[2][0])
res++;
if(board[0][0]==ch&&board[0][0]==board[1][1]&&board[1][1]==board[2][2])
res++;
if(board[0][2]==ch&&board[0][2]==board[1][1]&&board[1][1]==board[2][0])
res++;
if(board[1][0]==ch&&board[1][0]==board[1][1]&&board[1][1]==board[1][2])
res++;
if(board[2][0]==ch&&board[2][0]==board[2][1]&&board[2][1]==board[2][2])
res++;
if(board[0][1]==ch&&board[0][1]==board[1][1]&&board[1][1]==board[2][1])
res++;
if(board[0][2]==ch&&board[0][2]==board[1][2]&&board[1][2]==board[2][2])
res++;
if(res!=0)
return res;
else
return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
char mat[3][3];
int x=0,o=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>mat[i][j];
if(mat[i][j]=='X')
x++;
else if(mat[i][j]=='O')
o++;
}
}
if(x==o||x==o+1)
{
int xx=wins(mat,'X');
int oo=wins(mat,'O');
if(xx>=2||oo>=2)
cout<<"3"<<endl;
else if(xx&&oo)
{
cout<<"3"<<endl;
}
else if(xx)
{ if(x==o+1)
cout<<"1"<<endl;
else
cout<<"3"<<endl;
}
else if(oo)
{
if(x==o)
cout<<"1"<<endl;
else
cout<<"3"<<endl;
}
else
{ if(xx+oo==9)
cout<<"1"<<endl;
else
cout<<"2"<<endl;
}
}
else
{
cout<<"3"<<endl;
}
}
}
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
Should’nt it be 3? As count(‘X’)!=count(‘O’)+1 as first symbol starts with ‘X’
please check it where i am wrong
That still doesn’t compile.
I’m going to assume it’s this submission, in which case it gets the wrong answer for the testcase directly above your last post.
I am getting the same outputs but still compiler is still telling WA.
Post a link to your submission
Can you counter any test case which fails to pass in this?
https://www.codechef.com/viewsolution/46669468
1
__X
__X
OOX
Thanks man,it was a typo in my code i was struggling with this very badly now worked!
can anyone tell me which case I am missing
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int nu = 0, nx = 0, no = 0;
char a[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> a[i][j];
if (a[i][j] == '_')
nu++;
if (a[i][j] == 'X')
nx++;
if (a[i][j] == 'O')
no++;
}
}
int xwin = 0, owin = 0;
if ((a[0][0] == a[0][1]) && (a[0][0] == a[0][2]))
{
if (a[0][0] == 'O')
{
owin++;
}
else if (a[0][0] == 'X')
{
xwin++;
}
}
if ((a[1][0] == a[1][1]) && (a[1][0] == a[1][2]))
{
if (a[1][0] == 'O')
{
owin++;
}
else if (a[1][0] == 'X')
{
xwin++;
}
}
if ((a[2][0] == a[2][1]) && (a[2][0] == a[2][2]))
{
if (a[2][0] == 'O')
{
owin++;
}
else if (a[2][0] == 'X')
{
xwin++;
}
}
if ((a[0][0] == a[1][0]) && (a[0][0] == a[2][0]))
{
if (a[0][0] == 'O')
{
owin++;
}
else if (a[0][0] == 'X')
{
xwin++;
}
}
if ((a[0][1] == a[1][1]) && (a[0][1] == a[2][1]))
{
if (a[0][1] == 'O')
{
owin++;
}
else if (a[0][1] == 'X')
{
xwin++;
}
}
if ((a[0][2] == a[1][2]) && (a[0][2] == a[2][2]))
{
if (a[0][2] == 'O')
{
owin++;
}
else if (a[0][2] == 'X')
{
xwin++;
}
}
if ((a[0][0] == a[1][1]) && (a[0][0] == a[2][2]))
{
if (a[0][0] == 'O')
{
owin++;
}
else if (a[0][0] == 'X')
{
xwin++;
}
}
if ((a[2][0] == a[1][1]) && (a[2][0] == a[0][2]))
{
if (a[2][0] == 'O')
{
owin++;
}
else if (a[2][0] == 'X')
{
xwin++;
}
}
if (nu == 0)
{
if (nx == 5 && no == 4)
cout << "1" << endl;
else
cout << "3" << endl;
}
else if (nu != 0)
{
if ((xwin == 1 && owin == 0) && (nx - no == 1))
cout << "1" << endl;
else if ((xwin == 0 && owin == 1) && (nx == no))
cout << "1" << endl;
else if ((xwin == 0 && owin == 0) && (nx - no == 1 || nx - no == 0))
cout << "2" << endl;
else
cout << "3" << endl;
}
}
return 0;
}
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
ok
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int nu = 0, nx = 0, no = 0;
char a[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> a[i][j];
if (a[i][j] == '_')
nu++;
if (a[i][j] == 'X')
nx++;
if (a[i][j] == 'O')
no++;
}
}
int xwin = 0, owin = 0;
if ((a[0][0] == a[0][1]) && (a[0][0] == a[0][2]))
{
if (a[0][0] == 'O')
{
owin++;
}
else if (a[0][0] == 'X')
{
xwin++;
}
}
if ((a[1][0] == a[1][1]) && (a[1][0] == a[1][2]))
{
if (a[1][0] == 'O')
{
owin++;
}
else if (a[1][0] == 'X')
{
xwin++;
}
}
if ((a[2][0] == a[2][1]) && (a[2][0] == a[2][2]))
{
if (a[2][0] == 'O')
{
owin++;
}
else if (a[2][0] == 'X')
{
xwin++;
}
}
if ((a[0][0] == a[1][0]) && (a[0][0] == a[2][0]))
{
if (a[0][0] == 'O')
{
owin++;
}
else if (a[0][0] == 'X')
{
xwin++;
}
}
if ((a[0][1] == a[1][1]) && (a[0][1] == a[2][1]))
{
if (a[0][1] == 'O')
{
owin++;
}
else if (a[0][1] == 'X')
{
xwin++;
}
}
if ((a[0][2] == a[1][2]) && (a[0][2] == a[2][2]))
{
if (a[0][2] == 'O')
{
owin++;
}
else if (a[0][2] == 'X')
{
xwin++;
}
}
if ((a[0][0] == a[1][1]) && (a[0][0] == a[2][2]))
{
if (a[0][0] == 'O')
{
owin++;
}
else if (a[0][0] == 'X')
{
xwin++;
}
}
if ((a[2][0] == a[1][1]) && (a[2][0] == a[0][2]))
{
if (a[2][0] == 'O')
{
owin++;
}
else if (a[2][0] == 'X')
{
xwin++;
}
}
if (nu == 0)
{
if (nx == 5 && no == 4)
cout << "1" << endl;
else
cout << "3" << endl;
}
else if (nu != 0)
{
if ((xwin == 1 && owin == 0) && (nx - no == 1))
cout << "1" << endl;
else if ((xwin == 0 && owin == 1) && (nx == no))
cout << "1" << endl;
else if ((xwin == 0 && owin == 0) && (nx - no == 1 || nx - no == 0))
cout << "2" << endl;
else
cout << "3" << endl;
}
}
return 0;
}
Thanks
Consider the test input:
1
XXX
XXO
OOO
Thank you so much