Page 4 of 6

Re: 10196 - Check The Check

Posted: Sun Oct 18, 2009 8:09 pm
by lazyboy
dear ThanatosX....

I didn't check your code but my ACC code produces output as same as yours.

you used " char board[8][8]; "
try by increase the size of board[][] >8
Thanks.

Re: 10196 - Check The Check

Posted: Fri Oct 01, 2010 9:46 pm
by chackal_sjc
Hey guys,

My algorithm is getting WA but its output is correct when trying all kinds of inputs comparing to UVa toolkit website.
Here is my code http://ideone.com/GwoGP

Thank you

check the check

Posted: Fri Nov 12, 2010 11:06 am
by addnanoo
in the problem check the check , i keep getting a WA,
i checked every element in the chess bored ,and check the boundaries of each element...
:S any idea ?
here is my code
#include <iostream>

using namespace std;
void Pawn(char game[8][8]);
void Rook(char game[8][8]);
void Bishop(char game[8][8]);
void Knight(char game[8][8]);
int main(){
int count = 0;
char game[8][8];
bool k = false,K = false;
bool con = false;


int i, j;
while(!con ){
count++;
con = false;
for(i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
cin>>game[j];
if(game[j] != '.')
con = true;
}
}


if(con == false)
return 0;


Pawn(game);

Rook(game);

Bishop(game);

Knight(game);





for(i =0; i<8; i++)
{

for(j=0; j<8; j++)
{

if(game[j] == 'k')
k = true;
else if(game[j] == 'K')
K = true;


}

}

if( k == true && K == true || k == false && K == false)
cout<<"Game #"<<count<<": no king is in check."<<endl;
else if(k == true && K== false)
cout<<"Game #"<<count<<": white king is in check."<<endl;
else if (K == true && k== false)
cout<<"Game #"<<count<<": black king is in check."<<endl;


}


return 0;

}

void Pawn(char game[8][8]){

int i, j;
for(i =0; i<8; i++)
for(j=0; j<8; j++)
{
if(game[j] == 'p')
{
if( i<7)
{
if( j > 0 && game[i+1][j-1] == 'K')
game[i+1][j-1] = '*';
if( j < 7 && game[i+1][j+1] == 'K')
game[i+1][j+1] = '*';

}
}

if(game[j] == 'P')
{
if( i>0)
{
if( j > 0 && game[i-1][j-1] == 'k')
game[i-1][j-1] = '*';
if( j < 7 && game[i-1][j+1] == 'k')
game[i-1][j+1] = '*';
}
}

}
}







void Rook(char game[8][8])
{
int i, j, k;

for(i =0; i<8; i++)
for(j=0; j<8; j++)
{
if(game[j] == 'R' || game[j] == 'Q')
{
if(i<7)
for( k = i+1; k < 8; k++)
if(game[k][j] == 'k')
game[k][j] = '*';
else if(game[k][j] != '.')
break;


if(i>0)
for( k = i-1; k >= 0; k--)
if(game[k][j] == 'k')
game[k][j] = '*';
else if(game[k][j] != '.')
break;
if(j <7)
for( k = j-1; k >= 0; k--)
if(game[k] == 'k')
game[k] = '*';
else if(game[i][k] != '.')
break;
if(j > 0)
for( k = j+1; k < 8; k++)
if(game[i][k] == 'k')
game[i][k] = '*';
else if(game[i][k] != '.')
break;

}
}



for(i =0; i<8; i++)
for(j=0; j<8; j++)
{
if(game[i][j] == 'r' || game[i][j] == 'q')
{
if(i<7)
for( k = i+1; k < 8; k++)
if(game[k][j] == 'K')
game[k][j] = '*';
else if(game[k][j] != '.')
break;


if(i>0)
for( k = i+1; k >= 0; k--)
if(game[k][j] == 'K')
game[k][j] = '*';
else if(game[k][j] != '.' )
break;
if(j <7)
for( k = j-1; k >= 0; k--)
if(game[i][k] == 'K')
game[i][k] = '*';
else if(game[i][k] != '.')
break;
if(j > 0)
for( k = j+1; k < 8; k++)
if(game[i][k] == 'K')
game[i][k] = '*';
else if(game[i][k] != '.')
break;

}
}
}


void Bishop(char game[8][8])
{
int i, j;
int r, c;

for(i =0; i<8; i++)
for(j=0; j<8; j++)
{


if(game[i][j] == 'b' || game[i][j] == 'q')
{
r = i+1; c = j+1;
while( r <= 7 && c <= 7)
{
if(game[r][c] == 'K')
game[r][c] = '*';

else if(game[r][c] != '.')
break;
r++;c++;
}
r = i-1; c = j-1;


while( r >= 0 && c >=0)
{
if(game[r][c] == 'K')
game[r][c] = '*';
else if(game[r][c] != '.')
break;
r--;c--;
}
r = i+1; c = j-1;

while( r <= 7 && c >=0)
{
if(game[r][c] == 'K')
game[r][c] = '*';
else if(game[r][c] != '.')
break;
r++;c--;
}
r = i-1; c = j+1;

while( r >= 0 && c <=7)
{
if(game[r][c] == 'K')
game[r][c] = '*';
else if(game[r][c] != '.')
break;
r--;c++;
}
}

}


for(i =0; i<8; i++)
for(j=0; j<8; j++)
{


if(game[i][j] == 'B' || game[i][j] == 'Q')
{
r = i+1; c = j+1;
while( r <= 7 && c <= 7)
{
if(game[r][c] == 'k')
game[r][c] = '*';

else if(game[r][c] != '.')
break;
r++;c++;
}
r = i-1; c = j-1;


while( r >= 0 && c >=0)
{
if(game[r][c] == 'k')
game[r][c] = '*';
else if(game[r][c] != '.')
break;
r--;c--;
}
r = i+1; c = j-1;

while( r <= 7 && c >=0)
{
if(game[r][c] == 'k')
game[r][c] = '*';
else if(game[r][c] != '.')
break;
r++;c--;
}
r = i-1; c = j+1;

while( r >= 0 && c <=7)
{
if(game[r][c] == 'k')
game[r][c] = '*';
else if(game[r][c] != '.')
break;
r--;c++;
}
}

}

}
void Knight(char game[8][8])
{

int i,j;

for(i=0; i<8; i++)
for(j=0; j<8; j++)
{
if( game[i][j] == 'n')
{
if((i+2) <= 7)
{
if(j+1 <= 7)
if(game[i+2][j+1] == 'K')
game[i+2][j+1] = '*';
else if(game[i+2][j+1] != '.')
break;

if(j-1>=0)
if(game[i+2][j-1] == 'K')
game[i+2][j-1] = '*';
else if(game[i+2][j-1] != '.')
break;

}

if(i-2 <= 0)
{
if(j+1 <= 7)
if(game[i-2][j+1] == 'K')
game[i-2][j+1] = '*';
else if(game[i-2][j+1] != '.')
break;

if(j-1>=0)
if(game[i-2][j-1] == 'K')
game[i-2][j-1] = '*';
else if(game[i-2][j-1] != '.')
break;

}


if(j+2 <= 7)
{
if(i+1 <= 7)
if(game[i+1][j+2] == 'K')
game[i+1][j+2] = '*';
else if(game[i+1][j+2] != '.')
break;

if(i-1>=0)
if(game[i-1][j+2] == 'K')
game[i-1][j+2] = '*';
else if(game[i-1][j+2] != '.')
break;


}

if(j-2 >= 0)
{
if(i+1 <= 7)
if(game[i+1][j-2] == 'K')
game[i+1][j-2] = '*';
else if(game[i+1][j-2] != '.')
break;

if(i-1>=0)
if(game[i-1][j-2] == 'K')
game[i-1][j-2] = '*';
else if(game[i-1][j-2] != '.')
break;
}
}



if( game[i][j] == 'N')
{
if((i+2) <= 7)
{
if(j+1 <= 7)
if(game[i+2][j+1] == 'k')
game[i+2][j+1] = '*';
else if(game[i+2][j+1] != '.')
break;

if(j-1>=0)
if(game[i+2][j-1] == 'k')
game[i+2][j-1] = '*';
else if(game[i+2][j-1] != '.')
break;

}

if(i-2 <= 0)
{
if(j+1 <= 7)
if(game[i-2][j+1] == 'k')
game[i-2][j+1] = '*';
else if(game[i-2][j+1] != '.')
break;

if(j-1>=0)
if(game[i-2][j-1] == 'k')
game[i-2][j-1] = '*';
else if(game[i-2][j-1] != '.')
break;

}


if(j+2 <= 7)
{
if(i+1 <= 7)
if(game[i+1][j+2] == 'k')
game[i+1][j+2] = '*';
else if(game[i+1][j+2] != '.')
break;

if(i-1>=0)
if(game[i-1][j+2] == 'k')
game[i-1][j+2] = '*';
else if(game[i-1][j+2] != '.')
break;


}

if(j-2 >= 0)
{
if(i+1 <= 7)
if(game[i+1][j-2] == 'k')
game[i+1][j-2] = '*';
else if(game[i+1][j-2] != '.')
break;

if(i-1>=0)
if(game[i-1][j-2] == 'k')
game[i-1][j-2] = '*';
else if(game[i-1][j-2] != '.')
break;
}
}





}
}


Re: 10196 - Check The Check

Posted: Wed Jul 13, 2011 12:06 pm
by plamplam
Nice problem, although it actually tests your patience and how much cautious you are :)...May be I enjoyed solving this because I like to play chess :wink:
If you get Wrong Answer, just try the sample inputs posted by jud (Thanks jud nice I/O) on page 2. Be careful when you are checking whether the pawn threatens the king or not. And the problem does not say anything about cases like:

Code: Select all

...b....
......P.
.....P..  
........
....k...
........
........
..p....K
The problem could have been better if it had cases like this. As you can see, the black pawn reaches the last rank and so it can be promoted to a queen. Now if it is promoted to a queen/rook the white king is threatened. However the output for this problem should be no king is in check(There wont be cases like this don't be confused. I'm just trying to say if the problem mentioned that if a pawn reaches the last rank, it would be automatically promoted to a queen.)

Re: 10196 - Check The Check

Posted: Wed Jul 13, 2011 12:12 pm
by plamplam
And follow stcheung's advice. His 5th advice is very important (Actually it saves you a lot of time and your code will be shorter so there will be lesser probability for error to creep in). I created a 40 x 40 char array and stored the board in the middle of my array.

Re: 10196 - Check The Check

Posted: Mon Apr 09, 2012 6:37 am
by brianfry713
Input:

Code: Select all

...k....
........
...K....
...R....
........
........
........
........

........
........
........
........
........
........
........
........

Re: 10196 - Check The Check

Posted: Tue Sep 04, 2012 3:56 am
by kier.guevara
I tested all the cases but I still got wrong answer..
Here is my code:

Code: Select all

//code accepted
}

can you guys help me find my mistake?

Re: 10196 - Check The Check

Posted: Tue Sep 04, 2012 3:49 pm
by kier.guevara
Tried another solution but still wrong.
What is wrong with this?

Code: Select all

//code accepted

Re: 10196 - Check The Check

Posted: Wed Sep 05, 2012 12:05 am
by brianfry713
kier.guevara wrote:Tried another solution but still wrong.
What is wrong with this?
Doesn't match the sample I/O.

Re: 10196 - Check The Check

Posted: Wed Sep 05, 2012 12:07 am
by brianfry713
kier.guevara wrote:I tested all the cases but I still got wrong answer..
Here is my code:

can you guys help me find my mistake?
If row and column equal zero don't try to read board[row-1][column-1]

Re: 10196 - Check The Check

Posted: Wed Sep 05, 2012 9:44 am
by kier.guevara
Thanks brianfry! my code got accepted!

Re: 10196 - Check The Check

Posted: Wed Jan 09, 2013 1:49 pm
by connor
brianfry713 wrote:
kier.guevara wrote:Tried another solution but still wrong.
What is wrong with this?
Doesn't match the sample I/O.
i don't why my code got runtime error

plz help 3ks;


got AC with help from brianfry713

Re: 10196 - Check The Check

Posted: Wed Jan 09, 2013 10:47 pm
by brianfry713
Maybe there is an input like:

Code: Select all

k......K
........
pppppppp
pppppppp
pppppppp
pppppppp
pppppppp
pppppppp

........
........
........
........
........
........
........
........

Re: 10196 - Check The Check

Posted: Sat Jan 12, 2013 4:37 am
by connor
brianfry713 wrote:Maybe there is an input like:

Code: Select all

k......K
........
pppppppp
pppppppp
pppppppp
pppppppp
pppppppp
pppppppp

........
........
........
........
........
........
........
........

!!!great help!!!
got ac finally
printf("thank you ")
for(i=1;;i++)printf("very ");
printf("much!!!");

Re: 10196 - Check The Check

Posted: Wed Feb 27, 2013 1:44 pm
by raj
deleted...