ENG  RUS Timus Online Judge Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1334. Checkers

May be anyone will tell me what's wrong with this?
Posted by Vladimir Milenov Vasilev 20 Nov 2005 19:52
I read all the topics in the forum, but it doesn't seem serious to me the tests to be wrong - I thing, the problem is in me...So here is my program - if anyone has a little time, could  have a look at it - Wrong answer on test2....

#include <iostream.h>
#include <stdio.h>

int a,i,j;

int wins1(char x,char y, int id)
{
if ((x <= 'a') || (x >= 'h') || (y <= '1') || (y >= '8')) return 0;
if (a[x-'a'-1][y-'1'-1]+a[x-'a'+1][y-'1'+1]==2*(1-id)+1) return 1;
if (a[x-'a'-1][y-'1'+1]+a[x-'a'+1][y-'1'-1]==2*(1-id)+1) return 1;
return 0;
}

int wins(char x,char y, int id)
{
if (x < 'a' || x > 'h' || y < '1' || y > '8') return 0;
if ((x >= 'c') && (y >= '3') && (a[x-'a'-1][y-'1'-1]==2*(1-id)+1) && (a[x-'a'-2][y-'1'-2]==0)) return 1;
if ((x >= 'c') && (y <= '6') && (a[x-'a'-1][y-'1'+1]==2*(1-id)+1) && (a[x-'a'-2][y-'1'+2]==0)) return 1;
if ((x <= 'f') && (y >= '3') && (a[x-'a'+1][y-'1'-1]==2*(1-id)+1) && (a[x-'a'+2][y-'1'-2]==0)) return 1;
if ((x <= 'f') && (y <= '6') && (a[x-'a'+1][y-'1'+1]==2*(1-id)+1) && (a[x-'a'+2][y-'1'+2]==0)) return 1;
return 0;
}

int main()
{
char s, p;
p = 'a'-1;
p = '1'-1;
for(i = 0; i < 8; i++)
for (j = 0; j < 8; j++)
a[i][j] = 0;
for (i = 0; i < 32; i++)
{
gets(s);
if (s >='A' && s <= 'Z') s = s-'A'+'a';
a[s-'a'][s-'1'] = 2*(i%2)+1;
if (wins(p,p,1-(i%2)) == 1)
{     cout<<i+1<<endl;
return 0;
}
if (wins1(s,s,(i%2)) == 1)
{
cout<<i+1<<endl;
return 0;
}
p = s;
p = s;
p = s;
}
cout << "Draw" << endl;
return 0;
}