Page 2 of 6

Re: 10196 WA... very confused.

Posted: Fri Apr 09, 2004 10:34 am
by CDiMa
midra wrote:I have no idea of what the program must output if there is a white king adyacent to a black king....who hack?
From the problem's input statement:
...there won't be a configuration where both kings are in check.
Ciao!!!

Claudio

Posted: Sat Apr 10, 2004 7:54 pm
by midra
thanks... :D
but if there won't be an input with both king in hack, so Why I still got WA???

Michel
Chau

10196 WA! Any tricky test cases?

Posted: Wed Jan 05, 2005 10:40 am
by hhen926
I have tried all possible configurations I can think of, but I still got WA for this problem :-?

Posted: Fri Jan 07, 2005 6:19 am
by hhen926
In the question, it's given the movement of the king. Is it used for any test cases?
One of the constraints states that there is no configuration where two kings are in check.

Posted: Fri May 20, 2005 5:21 pm
by Alberto
Yes friend. Cut the "Uses Crt" and "clrscr"

10196 - test case

Posted: Sat Oct 15, 2005 12:15 am
by sunny
some 1 pls give me some tricky inputs for 10196. my code gives tons of WA.


#include<stdio.h>
#include<string.h>
#include<math.h>
char board[10][10],ch;


int rook(int row,int col,char piece)
{
int i;

for(i=row+1;i<8;i++){ if(board[col]!='.'){
if(board[col]==piece) return 1;
else break;
}
}
for(i=row-1;i>=0;i--){ if(board[col]!='.'){
if(board[col]==piece) return 1;
else break;
}
}

for(i=col+1;i<8;i++){ if(board[row]!='.'){
if(board[row]==piece) return 1;
else break;
}
}

for(i=col-1;i>=0;i--){ if(board[row]!='.'){
if(board[row]==piece) return 1;
else break;
}
}
return 0;
}
int bishop(int row,int col,char piece)
{
int i,j;

for(i=row+1,j=col+1;i<8 && j<8;i++,j++){
if(board[j]!='.'){
if(board[j]==piece) return 1;
else break;
}}

for(i=row+1,j=col-1;i<8 && j>=0;i++,j--){
if(board[i][j]!='.'){
if(board[i][j]==piece) return 1;
else break;
}}

for(i=row-1,j=col+1;i>=0 && j<8;i--,j++){
if(board[i][j]!='.'){
if(board[i][j]==piece) return 1;
else break;
}}

for(i=row-1,j=col-1;i>=0 && j>=0;i--,j--){
if(board[i][j]!='.'){
if(board[i][j]==piece) return 1;
else break;
}}

return 0;

}

int knight(int row,int col, char piece)
{
if(board[row+1][col+2]==piece || board[row+1][col-2]==piece ||
board[row-1][col+2]==piece || board[row-1][col+2]==piece ||
board[row+2][col+1]==piece || board[row+2][col-1]==piece ||
board[row-2][col+1]==piece || board[row-2][col-1]==piece) return 1;

return 0;

}

int main()
{
int i,j,brow,bcol,wrow,wcol,p,wcheck,bcheck;
long q=0;
re:
p=0,wcheck=0;bcheck=0,brow=0,bcol=0,wrow=0,wcol=0;

for(i=0;i<8;i++) scanf("%s",board[i]);




for(i=0;i<8;i++){
for(j=0;j<8;j++){
if(board[i][j]!='.') p=1;

if(board[i][j]=='k') {brow=i;bcol=j;}
else if(board[i][j]=='K') {wrow=i;wcol=j;}




}
}

if(p==1){

if(board[wrow-1][wcol+1]=='p' || board[wrow-1][wcol-1]=='p') wcheck=1;
else if(knight(wrow,wcol,'n')) wcheck=1;
else if(rook(wrow,wcol,'r')) wcheck=1;
else if(bishop(wrow,wcol,'b')) wcheck=1;
else if(rook(wrow,wcol,'q')) wcheck=1;
else if(bishop(wrow,wcol,'q')) wcheck=1;
/*
else if(board[wrow][wcol+1]=='k' || board[wrow][wcol-1]=='k' || board[wrow-1][wcol]=='k'||
board[wrow+1][wcol]=='k' || board[wrow+1][wcol+1]=='k' || board[wrow+1][wcol-1]=='k'
|| board[wrow-1][wcol+1]=='k' || board[wrow-1][wcol-1]=='k') wcheck=1;

*/

if(board[brow+1][bcol-1]=='P' || board[brow+1][bcol+1]=='P') bcheck=1;
else if(knight(brow,bcol,'N')) bcheck=1;
else if(rook(brow,bcol,'R')) bcheck=1;
else if(bishop(brow,bcol,'B')) bcheck=1;
else if(rook(brow,bcol,'Q')) bcheck=1;
else if(bishop(brow,bcol,'Q')) bcheck=1;
/*
else if(board[brow][bcol+1]=='K' || board[brow][bcol-1]=='K' || board[brow-1][bcol]=='K'||
board[brow+1][bcol]=='K' || board[brow+1][bcol+1]=='K' || board[brow+1][bcol-1]=='K'
|| board[brow-1][bcol+1]=='K' || board[brow-1][bcol-1]=='K') bcheck=1;

*/



if(wcheck==1) printf("Game #%ld: white king is in check.\n",++q);
else if (bcheck==1) printf("Game #%ld: black king is in check.\n",++q);

else if(wcheck==0 && bcheck==0)printf("Game #%ld: no king is in check.\n",++q);







goto re;


}


return 0;
}

Posted: Sun Nov 20, 2005 7:55 pm
by ayon
I saw the forum, many asks for help for this problem, but most of them is unanswered. Actually there was no tricky input. you have to implement very patiently. I got wa for several times for printing("Game %d#: "), that should be ("Game #%d: "), hope you none make such foolish mistakes. Here are some tips who are getting wa:
the king movement is totally unnecessary, bcos two kings cannot in attack simultaneously. the forward movements of pawn are also unnecessary, only the diagonals in account. moreover black pawn and white pawn is different. and for rook and bishop, you must check if the way is blocked by other pieces. queen -> rook || bishop :)

Posted: Sun Nov 20, 2005 7:58 pm
by ayon
Hi sunny,
You know judges are very clever, they gives lots of inputs to find your mistakes. Your program is 99.99% correct. Only in the knightMove you checked

Code: Select all

board[row-1][col+2]==piece || board[row-1][col+2]==piece
for twice, one must be

Code: Select all

board[row-1][col-2]==piece
Hope it works...

trip

Posted: Thu Jan 05, 2006 1:30 am
by sectroyer
Hi I keep getting Wa on this code :(
Please help. Thanks in advance.
#include <stdio.h>
char chess[60][60];
char is_sub_check(int x, int y,int dx,int dy, char sub,char uk)
{
int sx,sy,i1;
for(sx=x,sy=y,i1=0;i1<10;i1++)
{
sx+=dx;
sy+=dy;
if(chess[sx][sy]!='.')
{
if(chess[sx][sy]==('q'-sub))
return 1;
else if((uk==1) && (chess[sx][sy]==('b'-sub)))
return 1;
else if((uk==0) && (chess[sx][sy]==('r'-sub)))
return 1;
else
return 0;
}

}
return 0;
}
char is_knight(int x, int y, char k)
{
int i1;
char chk1[]={2,2,-2,-2,1,1,-1,-1};
char chk2[]={1,-1,1,-1,2,-2,2,-2};
for(i1=0;i1<8;i1++)
{
if(chess[x+chk1[i1]][y+chk2[i1]]==k)
return 1;
}
return 0;
}
char is_check(int x, int y, int pl)
{
int sub;
int i1;
char chk1[]={1,-1,1,-1,0,0,1,-1};
char chk2[]={1,-1,-1,1,1,-1,0,0};
if(pl==0)
sub=0x20;
else
sub=0;
if(pl==0)
{
if((chess[x+1][y-1]==('P')) || (chess[x+1][y+1]==('P')))
return 1;
}
else
{
if((chess[x-1][y-1]==('p')) || (chess[x-1][y+1]==('p')))
return 1;
}
if(is_knight(x,y,'n'-sub)==1)
return 1;
for(i1=0;i1<8;i1++)
{
if(is_sub_check(x,y,chk1[i1],chk2[i1],sub,i1<4))
return 1;
}
return 0;
}


int main(int argc, char *argv[])
{
char ch;
char ala;
char jasio[1000];
char X,x,Y,y,licz;
int i1,i2,i3,i4;
licz=0;
while(1)
{
X=Y=x=y=-1;
ala=0;
i1=0;
while(i1<(8*8))
{
ch=getchar();
switch(ch)
{
case 'K':
X=i1/8;
Y=i1%8;
chess[20+i1/8][20+i1%8]=ch;
i1++;
ala=1;
break;
case 'k':
x=i1/8;
y=i1%8;
chess[20+i1/8][20+i1%8]=ch;
i1++;
ala=1;
break;
case 'p':
case 'P':
case 'n':
case 'N':
case 'b':
case 'B':
case 'r':
case 'R':
case 'q':
case 'Q':
ala=1;
case '.':
chess[20+i1/8][20+i1%8]=ch;
i1++;
break;
default:
if(isspace(ch)==0)
{
sleep(12);
exit(0);
}
}
}

if((x == -1) || (X == -1) || (y == -1) || (Y == -1))
return 0;
licz++;
if(ala==0)
break;
if(is_check(20+X,20+Y,1)==1)
printf("Game #%d: white king is in check.\n",licz);
else if(is_check(20+x,20+y,0)==1)
printf("Game #%d: black king is in check.\n",licz);
else
printf("Game #%d: no king is in check.\n",licz);
}
return 0;
}

10196

Posted: Mon Mar 06, 2006 11:39 pm
by bossanova
I seem to still get WA, even with every test case I throw at this.

ideals / test cases I seem to be missing?

Code: Select all

#include <iostream> 
using namespace std;
#include <string>

int main(){
	int wlocx, wlocy, blocx, blocy;
	bool wcheck;
	wcheck = false;
	bool bcheck; 
	bcheck = false;
	bool done;
	done = false;
	string test[8];
	int i, j;
	long long game;
	game = 0;
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++)
		{
			cin >> test[i][j];	
			while (test[i][j] == ' ') {
				cin >> test[i][j];
			}
		}	
	}
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++) {
			if (test[i][j] != '.')
				done = true;
		}
	}
	while (done == true) {
	game++;
	for (i = 0; i < 8; i++)
	{
		for (j = 0; j < 8; j++) {
			if (test[j][i] == 'k') {
				blocx = j;
				blocy = i;
			}
			if (test[j][i] == 'K') {
				wlocx = j;
				wlocy = i;
			}
		}
	}
	
	
	for (i = wlocx; i < 8; i++) {
		if (test[i][wlocy] == 'P' 
			|| test[i][wlocy] == 'R' 
			|| test[i][wlocy] == 'Q' 
			|| test[i][wlocy] == 'N'
			|| test[i][wlocy] == 'B'
			|| test[i][wlocy] == 'b'
			|| test[i][wlocy] == 'n'
			|| test[i][wlocy] == 'p'
			|| test[i][wlocy] == 'k') {
			i = 10;
		}
		else if (test[i][wlocy] == 'r') {
			wcheck = true;
			i = 10;
		}
		else if (test[i][wlocy] == 'q') {
			wcheck = true;
			i = 10;
		}
	}
	
	for (i = wlocx; i >= 0; i--) {
		if (test[i][wlocy] == 'P' 
			|| test[i][wlocy] == 'R' 
			|| test[i][wlocy] == 'Q' 
			|| test[i][wlocy] == 'N'
			|| test[i][wlocy] == 'B'
			|| test[i][wlocy] == 'b'
			|| test[i][wlocy] == 'n'
			|| test[i][wlocy] == 'p'
			|| test[i][wlocy] == 'k') {
			i = -1;
		}
		else if (test[i][wlocy] == 'r') {
			wcheck = true;
			i = -1;
		}
		else if (test[i][wlocy] == 'q') {
			wcheck = true;
			i = -1;
		}
	}
	
	i = wlocx; j = wlocy;
	while (i < 8 && j < 8) {
		if (test[i][j] == 'P' 
			|| test[i][j] == 'R' 
			|| test[i][j] == 'Q' 
			|| test[i][j] == 'N'
			|| test[i][j] == 'B'
			|| test[i][j] == 'r'
			|| test[i][j] == 'n'
			|| test[i][j] == 'k'
			|| test[i][j] == 'p') {
			j = 10; 
		}
		else if (test[i][j] == 'b') {
			wcheck = true;
			j = 10;
		}
		else if (test[i][j] == 'q') {
			wcheck = true;
			j = 10;
		}
		i++;
		j++;
	}
	
	i = wlocx; j = wlocy;
	while (i < 8 && j >= 0) {
		if (test[i][j] == 'P' 
			|| test[i][j] == 'R' 
			|| test[i][j] == 'Q' 
			|| test[i][j] == 'N'
			|| test[i][j] == 'B'
			|| test[i][j] == 'r'
			|| test[i][j] == 'n'
			|| test[i][j] == 'k'
			|| test[i][j] == 'p') {
			j = -1; 
		}
		else if (test[i][j] == 'b') {
			wcheck = true;
			j = -1;
		}
		else if (test[i][j] == 'q') {
			wcheck = true;
			j = -1;
		}
		i++;
		j--;
	}
	

	i = wlocx; 
	j = wlocy;
	while (i >= 0 && j >= 0) {
		if (test[i][j] == 'P' 
			|| test[i][j] == 'R' 
			|| test[i][j] == 'Q' 
			|| test[i][j] == 'N'
			|| test[i][j] == 'B'
			|| test[i][j] == 'n'
			|| test[i][j] == 'k'
			|| test[i][j] == 'r'
			|| test[i][j] == 'p') {
			i = -1; 
		}
		else if (test[i][j] == 'b') {
			wcheck = true;
			i = -1;
		}
		else if (test[i][j] == 'q') {
			wcheck = true;
			i = -1;
		}
		i--;
		j--;
	}
	

	i = wlocx; j = wlocy;
	while (i >= 0 && j < 8) {
		if (test[i][j] == 'P' 
			|| test[i][j] == 'R' 
			|| test[i][j] == 'Q' 
			|| test[i][j] == 'N'
			|| test[i][j] == 'B'
			|| test[i][j] == 'n'
			|| test[i][j] == 'k'
			|| test[i][j] == 'r'
			|| test[i][j] == 'p') {
			i = -1; 
		}
		else if (test[i][j] == 'b') {
			wcheck = true;
			i = -1;
		}
		else if (test[i][j] == 'q') {
			wcheck = true;
			i = -1;
		}
		i--;
		j++;
	}
	

	
	i = wlocx; j = wlocy;
	

	if (i > 0 && j > 0) {
		if (test[i-1][j-1] == 'p')
			wcheck = true;

	}
	if (i > 0 && j < 7) {
		if (test[i-1][j+1] == 'p')
			wcheck = true;

	}


	if (i < 6 && j < 7)
		if (test[i+2][j+1] == 'n')
			wcheck = true;
	if (i < 6 && j > 0)
		if (test[i+2][j-1] == 'n')
			wcheck = true;
	if (i > 1 && j > 0)
		if (test[i-2][j-1] == 'n')
			wcheck = true;
	if (i > 1 && j < 7)
		if (test[i-2][j+1] == 'n')
			wcheck = true; 
	if (i < 7 && j < 6)
		if (test[i+1][j+2] == 'n')
			wcheck = true;
	if (i < 7 && j > 1)
		if (test[i+1][j-2] == 'n')
			wcheck = true;
	if (i > 0 && j > 1)
		if (test[i-1][j-2] == 'n')
			wcheck = true;
	if (i > 0 && j < 6)
		if (test[i-1][j+2] == 'n')
			wcheck = true; 

	


	for (i = blocx; i < 8; i++) {
		if (test[i][blocy] == 'p' 
			|| test[i][blocy] == 'r' 
			|| test[i][blocy] == 'q' 
			|| test[i][blocy] == 'n'
			|| test[i][blocy] == 'b'
			|| test[i][blocy] == 'N'
			|| test[i][blocy] == 'P'
			|| test[i][blocy] == 'B'
			|| test[i][blocy] == 'K') {
			i = 10;
		}
		else if (test[i][blocy] == 'R') {
			bcheck = true;
			i = 10;
		}
		else if (test[i][blocy] == 'Q') {
			bcheck = true;
			i = 10;
		}
	}
	
	
	for (i = blocx; i >= 0; i--) {
		if (test[i][blocy] == 'p' 
			|| test[i][blocy] == 'r' 
			|| test[i][blocy] == 'q' 
			|| test[i][blocy] == 'n'
			|| test[i][blocy] == 'b'
			|| test[i][blocy] == 'N'
			|| test[i][blocy] == 'P'
			|| test[i][blocy] == 'B'
			|| test[i][blocy] == 'K') {
			i = -1;
		}
		else if (test[i][blocy] == 'R') {
			bcheck = true;
			i = -1;
		}
		else if (test[i][blocy] == 'Q') {
			bcheck = true;
			i = -1;
		}
	}
	

	i = blocx; j = blocy;
	while (i < 8 && j < 8) {
		if (test[i][j] == 'p' 
			|| test[i][j] == 'r' 
			|| test[i][j] == 'q' 
			|| test[i][j] == 'n'
			|| test[i][j] == 'b'
			|| test[i][j] == 'N'
			|| test[i][j] == 'K'
			|| test[i][j] == 'R'
			|| test[i][j] == 'P') {
			j = 10; 
		}
		else if (test[i][j] == 'B') {
			bcheck = true;
			j = 10;
		}
		else if (test[i][j] == 'Q') {
			bcheck = true;
			j = 10;
		}
		i++;
		j++;
	}
	
	i = blocx; j = blocy;
	while (i < 8 && j >= 0) {
		if (test[i][j] == 'p' 
			|| test[i][j] == 'r' 
			|| test[i][j] == 'q' 
			|| test[i][j] == 'n'
			|| test[i][j] == 'b'
			|| test[i][j] == 'N'
			|| test[i][j] == 'K'
			|| test[i][j] == 'R'
			|| test[i][j] == 'P') {
			j = -1; 
		}
		else if (test[i][j] == 'B') {
			bcheck = true;
			j = -1;
		}
		else if (test[i][j] == 'Q') {
			bcheck = true;
			j = -1;
		}
		i++;
		j--;
	}
	
	i = blocx; j = blocy;
	while (i >= 0 && j >= 0) {
		if (test[i][j] == 'p' 
			|| test[i][j] == 'r' 
			|| test[i][j] == 'q' 
			|| test[i][j] == 'b'
			|| test[i][j] == 'b'
			|| test[i][j] == 'N'
			|| test[i][j] == 'K'
			|| test[i][j] == 'R'
			|| test[i][j] == 'P') {
			i = -1; 
		}
		else if (test[i][j] == 'B') {
			bcheck = true;
			i = -1;
		}
		else if (test[i][j] == 'Q') {
			bcheck = true;
			i = -1;
		}
		i--;
		j--;
	}
	
	i = blocx; j = blocy;
	while (i >= 0 && j < 8) {
		if (test[i][j] == 'p' 
			|| test[i][j] == 'r' 
			|| test[i][j] == 'q' 
			|| test[i][j] == 'n'
			|| test[i][j] == 'b'
			|| test[i][j] == 'N'
			|| test[i][j] == 'K'
			|| test[i][j] == 'R'
			|| test[i][j] == 'P') {
			i = -1; 
		}
		else if (test[i][j] == 'B') {
			bcheck = true;
			i = -1;
		}
		else if (test[i][j] == 'Q') {
			bcheck = true;
			i = -1;
		}
		i--;
		j++;
	}
	
	
	i = blocx; j = blocy;

	if (i < 7 && j < 7) {
		if (test[i+1][j+1] == 'P')  
			bcheck = true;
	}
	if (i < 7 && j > 0) {
		if (test[i+1][j-1] == 'P') 
			bcheck = true;
	}


	if (i < 6 && j < 7)
		if (test[i+2][j+1] == 'N')
			bcheck = true;
	if (i < 6 && j > 0)
		if (test[i+2][j-1] == 'N')
			bcheck = true;
	if (i > 1 && j > 0)
		if (test[i-2][j-1] == 'N')
			bcheck = true;
	if (i > 1 && j < 7)
		if (test[i-2][j+1] == 'N')
			bcheck = true; 
	if (i < 7 && j < 6)
		if (test[i+1][j+2] == 'N')
			bcheck = true;
	if (i < 7 && j > 1)
		if (test[i+1][j-2] == 'N')
			bcheck = true;
	if (i > 0 && j > 1)
		if (test[i-1][j-2] == 'N')
			bcheck = true;
	if (i > 0 && j < 6)
		if (test[i-1][j+2] == 'N')
			bcheck = true; 

	if (wcheck == true) {
		cout << "Game #" << game << ": white king is in check." << endl;
	}
	else if (bcheck == true) {
		cout << "Game #" << game << ": black king is in check." << endl;
	}
	else {
		cout << "Game #" << game << ": no king is in check." << endl;
	}
	done = false;
	wcheck = false;
	bcheck = false;
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++)
		{
			cin >> test[i][j];	
			while (test[i][j] == ' ') {
				cin >> test[i][j];
			}
		}	
	}

	for (i = 0; i < 8; i++) {
		for (j = 0; j< 8; j++) {
			if (test[i][j] != '.')
				done = true;
		}
	}
	i = 0;
	j = 0;
	wlocy = -1;
	wlocx = -1;
	blocy = -1;
	blocx = -1;
	}


	return 0;
}
	

10196 WA, I simply don't see it

Posted: Tue Jul 04, 2006 1:21 pm
by sklitzz
Hi,

I've been batling this task for a couple of hours now and I really don't see where is the bug in my code. I read a lot of posts wih people having the same problem. But if anyone could simply check it out 'cause I'm loosing my mind here. My code is so simple so I can't understand where could the bug be.

Code: Select all

includes and the defines;
using namespace std;

string polje[8];

bool is_end() {
	FOR( i, 0, 8 ) FOR( j, 0, 8 ) if( polje[i][j] != '.' ) return false;
	return true;
}

bool bpawn( int x, int y ) {
	if( x == 7 ) return false;
	if( polje[x+1][y-1] == 'K' ) return true;
	if( polje[x+1][y+1] == 'K' ) return true;
	return false;
}

bool wpawn( int x, int y ) {
	if( x == 0 ) return false;
	if( polje[x-1][y-1] == 'k' ) return true;
	if( polje[x-1][y+1] == 'k' ) return true;
	return false;
}

bool rook( int x, int y, char k ) {
	FOR( i, 0, 8 ) if( polje[x][i] == k ) return true;
	FOR( i, 0, 8 ) if( polje[i][y] == k ) return true;
	return false;
}

bool bishop( int x, int y, char k ) {
	bool ret = false;
	
	int nx = x, ny = y;
	while( nx != 8 && ny != 8 ) {
		if( polje[nx][ny] == k ) ret = true; 
		nx++; ny++;
	}
	
	nx = x; ny = y;
	while( nx >= 0 && ny != 8 ) {
		if( polje[nx][ny] == k ) ret = true;
		nx--; ny++;
	}
	
	nx = x; ny = y;
	while( nx >= 0 && ny >= 0 ) {
		if( polje[nx][ny] == k ) ret = true;
		nx--; ny--;
	}
	
	nx = x; ny = y;
	while( nx != 8 && ny >= 0 ) {
		if( polje[nx][ny] == k ) ret = true; 
		nx++; ny--;
	}
	
	return ret;		
}

bool queen( int x, int y, char k ) {
	bool ret = false;
	if( bishop( x, y, k ) ) ret = true;
	if( rook( x, y, k ) ) ret = true;
	return ret;
}

bool knight( int x, int y, char k ) {
	bool ret = false;

	int dx[] = { 1, 1, -1, -1, 2, 2, -2, -2 };
	int dy[] = { 2, -2, 2, -2, 1, -1, 1, -1 };
	
	FOR( i, 0, 8 ) {
		int nx = x + dx[i], ny = y + dy[i];
		if( nx < 0 || nx >= 8 || ny < 0 || ny >= 8 ) continue;
		
		if( polje[nx][ny] == k ) ret = true;
	}
	return ret;
}

int main() {
	int n = 0;
	while( 1 ) {
		n++;
		FOR( i, 0, 8 ) cin >> polje[i];
			
		if( is_end() ) break;
	
		bool black = false, white = false;		
		FOR( i, 0, 8 )
			FOR( j, 0, 8 ) 
				switch( polje[i][j] ) {
					case 'p' : if( bpawn( i, j ) ) white = true; break; 
					case 'P' : if( wpawn( i, j ) ) black = true; break;
					
					case 'r' : if( rook( i, j, 'K' ) ) white = true; break;
					case 'R' : if( rook( i, j, 'k' ) ) black = true; break;
					
					case 'b' : if( bishop( i, j, 'K' ) ) white = true; break;
					case 'B' : if( bishop( i, j, 'k' ) ) black = true; break;
					
					case 'q' : if( queen( i, j, 'K' ) ) white = true; break;
					case 'Q' : if( queen( i, j, 'k' ) ) black = true; break;
					
					case 'n' : if( knight( i, j, 'K' ) ) white = true; break;
					case 'N' : if( knight( i, j, 'k' ) ) black = true; break;
				}
		
		if( black ) cout << "Game #" << n << ": black king is in check." << endl;
		else if( white ) cout << "Game #" << n << ": white king is in check." << endl;
		else cout << "Game #" << n << ": no king is in check." << endl;
		
	}
	
	return 0;
}

10196 plz help me !!

Posted: Tue Jul 11, 2006 4:54 pm
by Bluefin
Dear everyone:
This is the first time I post. I keep getting WA on 10196 but I don't know why. Since I have stuggled with 10196 for many many hours, I hope someone can give me a hand !!!

Here's my code:

// deleted after ACC

I do hope someone would tell me what's wrong with my code.
Thank in advance!!! :D

Posted: Sat Jul 15, 2006 7:34 pm
by CodeMaker
Here i give you some input output, you can check with them...

intputs:

Code: Select all

K......k
........
........
........
........
........
........
.......b

K......k
........
..p.....
........
........
........
........
.......b

Kp.....k
prn.....
..p.....
........
........
........
........
.......b

K..R...k
........
..p.....
........
........
........
........
.......b

K.pr...k
b....q..
..p..nn.
........
..b.....
........
........
bq.....b

K..RB..k
.....R.P
..p.....
.......Q
........
........
........
.......b

......B.
........
..p.....
........
..Kpk..r
........
........
.......b

......P.
...K.k..
..p.....
........
........
........
........
.......b

........
...K....
pppppppp
..n.n...
........
........
.k......
.......b

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

........
........
........
........
........
........
........
........
outputs:

Code: Select all

Game #1: white king is in check.
Game #2: no king is in check.
Game #3: white king is in check.
Game #4: black king is in check.
Game #5: no king is in check.
Game #6: no king is in check.
Game #7: no king is in check.
Game #8: no king is in check.
Game #9: white king is in check.
Game #10: no king is in check.

Posted: Mon Jul 17, 2006 8:21 am
by Bluefin
I've solved my problem. FINALLY !!
Anyway, thanks for your reply.
It really helps :lol:

10196

Posted: Mon Oct 09, 2006 11:11 am
by _Vardan_
Could anyone help me on this problem, please. I keep getting WA, though I've checked many test cases and all of them are giving correct answers.
Here's my code, thanks in advance.

Code: Select all


#include <iostream.h>

void main()
{
	bool t;
	char c[8][8];
	register int i=0, j=0;
	int i_temp, j_temp, d=0;


	
hi: t=true; d++;
   while(cin>>c[0][0]>>c[0][1]>>c[0][2]>>c[0][3]>>c[0][4]>>c[0][5]>>c[0][6]>>c[0][7]
			>>c[1][0]>>c[1][1]>>c[1][2]>>c[1][3]>>c[1][4]>>c[1][5]>>c[1][6]>>c[1][7]
			>>c[2][0]>>c[2][1]>>c[2][2]>>c[2][3]>>c[2][4]>>c[2][5]>>c[2][6]>>c[2][7]
			>>c[3][0]>>c[3][1]>>c[3][2]>>c[3][3]>>c[3][4]>>c[3][5]>>c[3][6]>>c[3][7]
			>>c[4][0]>>c[4][1]>>c[4][2]>>c[4][3]>>c[4][4]>>c[4][5]>>c[4][6]>>c[4][7]
			>>c[5][0]>>c[5][1]>>c[5][2]>>c[5][3]>>c[5][4]>>c[5][5]>>c[5][6]>>c[5][7]
			>>c[6][0]>>c[6][1]>>c[6][2]>>c[6][3]>>c[6][4]>>c[6][5]>>c[6][6]>>c[6][7]
			>>c[7][0]>>c[7][1]>>c[7][2]>>c[7][3]>>c[7][4]>>c[7][5]>>c[7][6]>>c[7][7])

				
		           
	{	
		for(i=0; i<8; i++)
			 for(j=0; j<8; j++)
				 if(c[i][j]!='.')
						 t=false;

					 
					 if(t)

						 break;

					 else
					 {
			              for(i=0; i<8; i++)
				              for(j=0; j<8; j++)
								  if(c[i][j]=='k')
								  {
									  i_temp=i;
								      j_temp=j;
								  }
								  
							

								  i=i_temp;
								  j=j_temp;

				while((i++)!=7 && (j++)!=7 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='B'))
					if(c[i][j]=='Q' || c[i][j]=='B')
					{cout << "Game #" << d <<": black king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

				while((i--)!=0 && (j--)!=0 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='B'))		
					if(c[i][j]=='Q' || c[i][j]=='B')
					{cout << "Game #" << d <<": black king is in check.\n";	goto hi;}
					


								  i=i_temp;
								  j=j_temp;

				while((i--)!=0 && (j++)!=7 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='B'))
					if(c[i][j]=='Q' || c[i][j]=='B')
					{cout << "Game #" << d <<": black king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

				while((i++)!=7 && (j--)!=0 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='B'))		
					if(c[i][j]=='Q' || c[i][j]=='B')
					{cout << "Game #" << d <<": black king is in check.\n"; goto hi;}
					
								  i=i_temp;
								  j=j_temp;

				while((j++)!=7 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='R'))
					if(c[i][j]=='Q' || c[i][j]=='R')
					{cout << "Game #" << d <<": black king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

				while((j--)!=0 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='R'))		
					if(c[i][j]=='Q' || c[i][j]=='R')
					{cout << "Game #" << d <<": black king is in check.\n"; goto hi;}
					
								  i=i_temp;
								  j=j_temp;

				while((i++)!=7 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='R'))
					if(c[i][j]=='Q' || c[i][j]=='R')
					{cout << "Game #" << d <<": black king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

				while((i--)!=0 && (c[i][j]=='.' || c[i][j]=='Q' || c[i][j]=='R'))		
					if(c[i][j]=='Q' || c[i][j]=='R')
					{cout << "Game #" << d <<": black king is in check.\n"; goto hi;}
					
                                  i=i_temp;
								  j=j_temp;

								  if(c[i+1][j+1]=='P' || c[i+1][j-1]=='P')
								  {cout << "Game #" << d <<": black king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

								  if(c[i+2][j+1]=='N' || c[i+2][j-1]=='N'
									  || c[i+1][j-2]=='N' || c[i-1][j-2]=='N'
									  || c[i-2][j-1]=='N' || c[i-2][j+1]=='N'
									  || c[i-1][j+2]=='N' || c[i+1][j+2]=='N')
								  {cout << "Game #" << d <<": black king is in check.\n"; goto hi;}




                         for(i=0; i<8; i++)
				              for(j=0; j<8; j++)
								  if(c[i][j]=='K')
								  {
									  i_temp=i;
								      j_temp=j;
								  }
							

								  i=i_temp;
								  j=j_temp;

				while((i++)!=7 && (j++)!=7 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='b'))
					if(c[i][j]=='q' || c[i][j]=='b')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}
                                  i=i_temp;
								  j=j_temp;

				while((i--)!=0 && (j--)!=0 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='b'))		
					if(c[i][j]=='q' || c[i][j]=='b')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}
					


								  i=i_temp;
								  j=j_temp;

				while((i--)!=0 && (j++)!=7 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='b'))
					if(c[i][j]=='q' || c[i][j]=='b')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}
                                  i=i_temp;
								  j=j_temp;

				while((i++)!=7 && (j--)!=0 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='b'))		
					if(c[i][j]=='q' || c[i][j]=='b')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}
					
								  i=i_temp;
								  j=j_temp;

				while((j++)!=7 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='r'))
					if(c[i][j]=='q' || c[i][j]=='r')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

				while((j--)!=0 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='r'))		
					if(c[i][j]=='q' || c[i][j]=='r')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}
					
								  i=i_temp;
								  j=j_temp;

				while((i++)!=7 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='r'))
					if(c[i][j]=='q' || c[i][j]=='r')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

				while((i--)!=0 && (c[i][j]=='.' || c[i][j]=='q' || c[i][j]=='r'))		
					if(c[i][j]=='q' || c[i][j]=='r')
					{cout << "Game #" << d <<": white king is in check.\n"; goto hi;}
					
                                  i=i_temp;
								  j=j_temp;

								  if(c[i-1][j-1]=='p' || c[i-1][j+1]=='p')
								  {cout << "Game #" << d <<": white king is in check.\n"; goto hi;}

                                  i=i_temp;
								  j=j_temp;

								  if(c[i+2][j+1]=='n' || c[i+2][j-1]=='n'
									  || c[i+1][j-2]=='n' || c[i-1][j-2]=='n'
									  || c[i-2][j-1]=='n' || c[i-2][j+1]=='n'
									  || c[i-1][j+2]=='n' || c[i+1][j+2]=='n')
                                  {cout << "Game #" << d <<": white king is in check.\n"; goto hi;}

								  cout << "Game #" << d <<": no king is in check.\n"; goto hi;


				


					 }
	}
}














[/code]