10196 - Check The Check
Moderator: Board moderators
Re: 10196 - Check The Check
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.
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.
-
- New poster
- Posts: 2
- Joined: Wed Jun 09, 2010 5:53 am
Re: 10196 - Check The Check
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
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
UNIFEI - Universidade Federal de Itajubá, Brazil
check the check
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
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
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 
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:
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.)


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
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
Re: 10196 - Check The Check
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.
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
Input:
Code: Select all
...k....
........
...K....
...R....
........
........
........
........
........
........
........
........
........
........
........
........
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 30
- Joined: Thu Jul 19, 2012 11:24 pm
Re: 10196 - Check The Check
I tested all the cases but I still got wrong answer..
Here is my code:
can you guys help me find my mistake?
Here is my code:
Code: Select all
//code accepted
}
Last edited by kier.guevara on Wed Sep 05, 2012 9:42 am, edited 1 time in total.
-
- New poster
- Posts: 30
- Joined: Thu Jul 19, 2012 11:24 pm
Re: 10196 - Check The Check
Tried another solution but still wrong.
What is wrong with this?
What is wrong with this?
Code: Select all
//code accepted
Last edited by kier.guevara on Wed Sep 05, 2012 9:43 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
Doesn't match the sample I/O.kier.guevara wrote:Tried another solution but still wrong.
What is wrong with this?
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
If row and column equal zero don't try to read board[row-1][column-1]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?
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 30
- Joined: Thu Jul 19, 2012 11:24 pm
Re: 10196 - Check The Check
Thanks brianfry! my code got accepted!
Re: 10196 - Check The Check
i don't why my code got runtime errorbrianfry713 wrote:Doesn't match the sample I/O.kier.guevara wrote:Tried another solution but still wrong.
What is wrong with this?
plz help 3ks;
got AC with help from brianfry713
Last edited by connor on Sat Jan 12, 2013 4:38 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
Maybe there is an input like:
Code: Select all
k......K
........
pppppppp
pppppppp
pppppppp
pppppppp
pppppppp
pppppppp
........
........
........
........
........
........
........
........
Check input and AC output for thousands of problems on uDebug!
Re: 10196 - Check The Check
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
deleted...
Last edited by raj on Tue Mar 05, 2013 11:41 pm, edited 3 times in total.