Posted: Sun Jan 14, 2007 10:56 am
No problem. Can you remove your code?
Code: Select all
3
XXX
.X.
OOO
XXX
.X.
OOO
X.O
...
O.X
Two g's in this question.am i missin anythin?
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;
}
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!
Code: Select all
removed after ac...
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;
}
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;
}
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