10363 - Tic Tac Toe
Moderator: Board moderators
- little joey
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
10363-wa- help anyone!!
i have solved this problem taking help from the VIJAY's code .but im gettin WA,even though my code is giving correct output. i have also checked my code with the test inpu/outout [Jemerson] and my code is givin correct output.plz some one help me find out the wrong part.here is my code:
Last edited by shaqira on Fri Jan 19, 2007 12:27 am, edited 1 time in total.
[ only a beginner.......]
First off, 'main' must return 'int'. Just say no to compilers who think otherwise.
Test your code with this input:
It outputs 'yesno' to the first case, and a blank line to the last one (when it's fed to it separately); and apparantly can't handle multiple cases (1st and 2nd cases are identical, and so should be the output of your program for them.)
Test your code with this input:
Code: Select all
3
XXX
.X.
OOO
XXX
.X.
OOO
X.O
...
O.X
10363 still wa!
thnx mf, for givin me suggestion.now i hav changed my code but its still
givin wa
.am i missin anythin?plz help
here is my modified code:
#include<stdio.h>
#include<string>
int main()
{
char board[3][3];
int test,i,r,c,co,cx,len;
bool xwin,owin;
scanf("%d\n",&test);
while(test--)
{
for(i=0;i<3;i++)
{
gets(board);
len=strlen(board[0]);
if(len==0)
{
i=-1;
continue;
}
}
cx=co=0;
owin=xwin=0;
for(r=0;r<3;r++)
for(c=0;c<3;c++)
{
if(board[r][c]=='X')
cx++;
if(board[r][c]=='O')
co++;
}
if((board[0][0]=='O')&&(board[0][1]=='O')&&(board[0][2]=='O'))
owin=1;
if((board[1][0]=='O')&&(board[1][1]=='O')&&(board[1][2]=='O'))
owin=1;
if((board[2][0]=='O')&&(board[2][1]=='O')&&(board[2][2]=='O'))
owin=1;
if((board[0][0]=='O')&&(board[1][0]=='O')&&(board[2][0]=='O'))
owin=1;
if((board[0][1]=='O')&&(board[1][1]=='O')&&(board[2][1]=='O'))
owin=1;
if((board[0][2]=='O')&&(board[1][2]=='O')&&(board[2][2]=='O'))
owin=1;
if((board[0][0]=='O')&&(board[1][1]=='O')&&(board[2][2]=='O'))
owin=1;
if((board[2][0]=='O')&&(board[1][1]=='O')&&(board[0][2]=='O'))
owin=1;
if((board[0][0]=='X')&&(board[0][1]=='X')&&(board[0][2]=='X'))
xwin=1;
if((board[1][0]=='X')&&(board[1][1]=='X')&&(board[1][2]=='X'))
xwin=1;
if((board[2][0]=='X')&&(board[2][1]=='X')&&(board[2][2]=='X'))
xwin=1;
if((board[0][0]=='X')&&(board[1][0]=='X')&&(board[2][0]=='X'))
xwin=1;
if((board[0][1]=='X')&&(board[1][1]=='X')&&(board[2][1]=='X'))
xwin=1;
if((board[0][2]=='X')&&(board[1][2]=='X')&&(board[2][2]=='X'))
xwin=1;
if((board[0][0]=='X')&&(board[1][1]=='X')&&(board[2][2]=='X'))
xwin=1;
if((board[2][0]=='X')&&(board[1][1]=='X')&&(board[0][2]=='X'))
xwin=1;
if(co>cx)
printf("no");
else if(co==cx)
{
if(xwin==1 && owin==1)
printf("no");
else if(xwin==1 && owin==0)
printf("no");
else if(xwin==0 && owin==1)
printf("yes");
else
printf("no");
}
else if(cx==co+1)
{
if(xwin==1 && owin==0)
printf("yes");
else
printf("no");
}
else
printf("no");
printf("\n");
}
return 1;
}
givin wa

here is my modified code:
#include<stdio.h>
#include<string>
int main()
{
char board[3][3];
int test,i,r,c,co,cx,len;
bool xwin,owin;
scanf("%d\n",&test);
while(test--)
{
for(i=0;i<3;i++)
{
gets(board);
len=strlen(board[0]);
if(len==0)
{
i=-1;
continue;
}
}
cx=co=0;
owin=xwin=0;
for(r=0;r<3;r++)
for(c=0;c<3;c++)
{
if(board[r][c]=='X')
cx++;
if(board[r][c]=='O')
co++;
}
if((board[0][0]=='O')&&(board[0][1]=='O')&&(board[0][2]=='O'))
owin=1;
if((board[1][0]=='O')&&(board[1][1]=='O')&&(board[1][2]=='O'))
owin=1;
if((board[2][0]=='O')&&(board[2][1]=='O')&&(board[2][2]=='O'))
owin=1;
if((board[0][0]=='O')&&(board[1][0]=='O')&&(board[2][0]=='O'))
owin=1;
if((board[0][1]=='O')&&(board[1][1]=='O')&&(board[2][1]=='O'))
owin=1;
if((board[0][2]=='O')&&(board[1][2]=='O')&&(board[2][2]=='O'))
owin=1;
if((board[0][0]=='O')&&(board[1][1]=='O')&&(board[2][2]=='O'))
owin=1;
if((board[2][0]=='O')&&(board[1][1]=='O')&&(board[0][2]=='O'))
owin=1;
if((board[0][0]=='X')&&(board[0][1]=='X')&&(board[0][2]=='X'))
xwin=1;
if((board[1][0]=='X')&&(board[1][1]=='X')&&(board[1][2]=='X'))
xwin=1;
if((board[2][0]=='X')&&(board[2][1]=='X')&&(board[2][2]=='X'))
xwin=1;
if((board[0][0]=='X')&&(board[1][0]=='X')&&(board[2][0]=='X'))
xwin=1;
if((board[0][1]=='X')&&(board[1][1]=='X')&&(board[2][1]=='X'))
xwin=1;
if((board[0][2]=='X')&&(board[1][2]=='X')&&(board[2][2]=='X'))
xwin=1;
if((board[0][0]=='X')&&(board[1][1]=='X')&&(board[2][2]=='X'))
xwin=1;
if((board[2][0]=='X')&&(board[1][1]=='X')&&(board[0][2]=='X'))
xwin=1;
if(co>cx)
printf("no");
else if(co==cx)
{
if(xwin==1 && owin==1)
printf("no");
else if(xwin==1 && owin==0)
printf("no");
else if(xwin==0 && owin==1)
printf("yes");
else
printf("no");
}
else if(cx==co+1)
{
if(xwin==1 && owin==0)
printf("yes");
else
printf("no");
}
else
printf("no");
printf("\n");
}
return 1;
}
[ only a beginner.......]
Re: 10363 still wa!
Why are you returning a 1 in your code?shaqira wrote:thnx mf, for givin me suggestion.now i hav changed my code but its still
givin wa.am i missin anythin?plz help
here is my modified code:
return 1;
}
10363
bcoz main() itself is a function and every function got a prototype and a return type. i have written 'int main()' which means main is a function which returns any integer at the end of the function.so u can return any
int at the end of ur code.as u can also write 'return 2' or 'return 0' or 'return 1000' .
n a special thnx to 'mf' for helpin me to find out wat i missed[ 2 g indeed]

int at the end of ur code.as u can also write 'return 2' or 'return 0' or 'return 1000' .
n a special thnx to 'mf' for helpin me to find out wat i missed[ 2 g indeed]

[ only a beginner.......]
thnx mf
thnx mf, atlast my code got accepted.
how come i missed the simplest input...
thnx again [ u must b wonderin y im thankin u so much ..coz u r da first
person to reply my post
, i didnt get any reply for my previous 2 posts
]

how come i missed the simplest input...

thnx again [ u must b wonderin y im thankin u so much ..coz u r da first
person to reply my post


[ only a beginner.......]
UVa's judge doesn't care about main()'s return value. But some other judges (like, spoj.pl), do and expect main to return 0.vijay03 wrote:I thought unless u returned a zero, the judge assumed your program was not running properly. I didnt know we could even return 1000 if we wanted!
Edit: this is no longer true, new UVa's judge expects a zero exit code :)
Re: 10363 - Tic Tac Toe
Can't seem to get the logic right.
If O wins,
number of X == number of O and X does not win.
If X wins,
number of X == number of O + 1 and O does not win.
Otherwise,
as long as number of X >= number of O, it is correct. <<--- this is wrong
If O wins,
number of X == number of O and X does not win.
If X wins,
number of X == number of O + 1 and O does not win.
Otherwise,
as long as number of X >= number of O, it is correct. <<--- this is wrong
Code: Select all
removed after ac...
10363 - Tic Tac Toe
Can anyone please help me with my code ?
M getting W/A
m i missing any important part?
thanks in advance
M getting W/A

m i missing any important part?
thanks in advance
Code: Select all
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string.h>
using namespace std;
#define fo(i,start,end) for(int i=start;i<end;i++)
#define szv(vector) vector.size()
#define sz(string) string.size();
#define rv(string) reverse(string.begin(),string.end())
typedef map<char,int> mp;
mp v_wins(char a[3][3])
{
map <char,int> c;
map <char,int> rslt;
c['X']=0;
c['O']=0;
rslt['X']=0;
rslt['O']=0;
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
if(a[i][j]==a[i][j+1]) {c[a[i][j]]++;}
else c[a[i][j]]=0;
}
if(c[a[i][j]]==2&&rslt[a[i][j]]!=1) {rslt[a[i][j]]=1;c[a[i][j]]=0;}
}
return rslt;
}
mp wins(char a[3][3])
{
map <char,int> count;
map <char,int> result;
int i,j;
// else
{
count['X']=0;
count['O']=0;
result['X']=0;
result['O']=0;
for(j=0;j<3;j++)
{
for(i=0;i<2;i++)
{
if(a[i][j]==a[i+1][j]) {count[a[i][j]]++;}
else{count[a[i][j]]=0;}
}
if((count[a[i][j]]==2)&&(result[a[i][j]]!=1)) {result[a[i][j]]=1;count[a[i][j]]=0;}
}
// result['P']=0;
return result;
}
}
int main()
{
char grid[3][3];
memset(grid,'.',sizeof(grid));
map <char,int> num;
int kase;
bool yes=true;
//freopen("tic.txt","r",stdin);
cin>>kase;
while(kase>0)
{ yes=true;
num['X']=0;
num['O']=0;
fo(i,0,3)
{
fo(j,0,3)
cin>>grid[i][j];
}
fo(i,0,3)
{
fo(j,0,3)
{
num[grid[i][j]]++;
}
}
map <char,int> digo;
digo['X']=0;
digo['O']=0;
if((grid[0][0]==grid[1][1])&&(grid[1][1]==grid[2][2])) digo[grid[0][0]]=1;
else if((grid[0][2]==grid[1][1])&&(grid[1][1]==grid[2][0])) digo[grid[0][2]]=1;
//cout<<"NUmber of X: "<<num['X']<<endl;
//cout<<"NUmber of O: "<<num['O']<<endl;
map <char,int> won;
map <char,int> v_w;
won=wins(grid);
// cout<<endl;
// cout<<"wX: "<<won['X']<<endl;
//cout<<"wO: "<<won['O']<<endl;
if((won['X']!=1)&&(won['O']!=1)) {v_w=v_wins(grid);} //cout<<v_w['X']<<endl;cout<<v_w['O']<<endl;
//if(won['X']==1&&won['O']==1) cout<<"NO"<<endl;
//else if(v_w['X']==1&&v_w['O']==1) cout<<"NO"<<endl;
//else cout<<"YES"<<endl;
bool x_wins=false;
bool o_wins=false;
if(won['X']==1||v_w['X']==1||digo['X']==1) x_wins=true;
if(won['O']==1||v_w['O']==1||digo['O']==1) o_wins=true;
// cout<<"x_wins: "<<x_wins<<endl;
//cout<<"o_wins: "<<o_wins<<endl;
if((num['X']-num['O'])>1) {yes=false;} //cout<<"1"<<endl;}
else if(num['X']<num['O']) {yes=false;}//cout<<"x less"<<endl;}
else if(x_wins==true&&o_wins==true) {yes=false;}// cout<<"both wins"<<endl;}
else if(x_wins==true&&(num['X']-num['O'])>1) {yes=false;}// cout<<"x wins but diff"<<endl;}
else if(o_wins==true&&(num['X']!=num['O'])) {yes=false;}// cout<<"o wins"<<endl;}
if(yes==false) cout<<"no"<<endl;
else if(yes==true) cout<<"yes"<<endl;
num.clear();
yes=true;
if(kase>1)
{
cout<<endl;
}
kase--;
}
return 0;
}
Re: 10363 - Tic Tac Toe
Getting WA... but why??
please help me
Code: Select all
/*in the name of Allah */
# include <list>
# include <deque>
# include <bitset>
# include <algorithm>
# include <functional>
# include <numeric>
# include <utility>
# include <sstream>
# include <iostream>
# include <iomanip>
# include <cstdio>
# include <cmath>
# include <cstdlib>
# include <ctime>
# include <set>
# include <map>
# include <cmath>
# include <queue>
# include <limits>
# include <stack>
# include <vector>
# include <cstring>
# include <cstdio>
using namespace std;
# define MEM(array,w) memset(array,w,sizeof array)
# define fr(i,a,b) for(int (i) = a ; i < b ; i++)
# define SET set<int>::iterator it = s.begin(); it != s.end();it++
# define ULL unsigned long long
# define eps 1e-9
# define SS stringstream
# define PR pair<int , int>
# define all(c) (c).begin(), (c).end()
# define maxint 1 << 31 - 1
# define FOR(i, a, b) for (int i=a; i<b; i++)
# define REP(i, a) FOR(i, 0, a)
# define rive(s) reverse(s.begin(),s.end())
# define OK(R,C) if(i>=0 && j>=0 && j<=C && i<=R)
template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isprime(int n){if( n<2) return 0;for( int i=2; i*i<=n ; i++)if(n%i==0)return 0; return 1;return 0;}
int pel(string s){string t;t=s;reverse(t.begin(),t.end());if(s==t)return 1;return 0;}
char tic[3][3];
int x,o;
int xx,oo;
void tictoc()
{
x=o=0;
if(tic[0][0]==tic[0][1] && tic[0][1]==tic[0][2])if(tic[0][0]=='X')x++;else if(tic[0][0]=='O')o++;//"""
if(tic[1][0]==tic[1][1] && tic[1][1]==tic[1][2])if(tic[1][0]=='X')x++;else if(tic[1][0]=='O')o++;//"""---
if(tic[2][0]==tic[2][1] && tic[2][1]==tic[2][2])if(tic[2][0]=='X')x++;else if(tic[2][0]=='O')o++;//"""---___
if(tic[0][0]==tic[1][0] && tic[1][0]==tic[2][0])if(tic[0][0]=='X')x++;else if(tic[0][0]=='O')o++;//|
if(tic[0][1]==tic[1][1] && tic[1][1]==tic[2][1])if(tic[0][1]=='X')x++;else if(tic[0][1]=='O')o++;// |
if(tic[0][2]==tic[1][2] && tic[1][2]==tic[2][2])if(tic[0][2]=='X')x++;else if(tic[0][2]=='O')o++;// |
if(tic[0][0]==tic[1][1] && tic[1][1]==tic[2][2])if(tic[2][2]=='X')x++;else if(tic[2][2]=='O')o++;//"-_
if(tic[2][0]==tic[1][1] && tic[1][1]==tic[0][2])if(tic[2][0]=='X')x++;else if(tic[2][0]=='O')o++;//_-"
}
int main()
{
int n,i,j,k;
scanf("%d\n",&n);
bool s=0;
bool f;
for( k=0;k<n;k++){
// if(s==1)cout<<endl;s=1;
f=false;xx=0,oo=0;
for(i=0;i<3;i++)
{
for( j=0;j<3;j++)
{
cin>>tic[i][j];
if(tic[i][j]=='X')xx++;
else if(tic[i][j]=='O')oo++;
}
getchar();
}
tictoc();
//cout<<x<<" "<<o<<" "<<xx<<" "<<oo<<endl;
if(x==1 && o==0 && xx==(oo+1))f=true;
else if(o==1 && x==0 && xx==oo)f=true;
else if(x==0 && o==0 && xx==(oo+1))f=true;
if(f)cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
Re: 10363 - Tic Tac Toe
Code: Select all
34
XXX
XOO
XOO
OXX
XOO
XXO
X..
X..
X..
X..
X..
O..
X.X
...
.X.
O.O
...
.O.
X.O
XO.
XOX
X.O
XOO
XXX
OXO
XXX
OXO
XXX
.O.
.O.
OOO
.X.
.X.
XOX
OXO
XOX
XXX
OOO
X.O
X.O
..X
X..
X.X
.OO
XOO
X.X
OO.
X.X
X.O
O.X
X.O
X.O
OO.
XXX
X.O
O.X
OOX
X.O
O..
XXO
X.O
O.O
X..
...
...
...
...
.X.
...
...
.O.
...
OO.
XXO
X.O
XXX
XXX
XXX
OOO
OOO
OOO
.O.
XXX
.O.
.X.
OOO
.X.
X.O
.X.
O.X
OXO
OXX
X.O
XXX
.OO
OX.
OOO
.XX
X.X
XO.
XO.
XOO
Code: Select all
yes
no
no
yes
no
no
yes
no
yes
yes
no
yes
no
no
no
no
yes
yes
no
yes
no
yes
yes
no
no
no
no
yes
no
yes
yes
yes
no
no
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson