10196 - Check The Check
Moderator: Board moderators
10196 - Check The Check
whats the problem with this one ???????? i'm tired of it
[cpp]
#include<stdio.h>
#include<string.h>
enum {B=0,W};
int drR[]={1,0,-1, 0};
int dcR[]={0,1, 0,-1};
int drB[]={ 1,1,-1,-1};
int dcB[]={-1,1, 1,-1};
int drN[]={ 1, 2,2,1,-1,-2,-2,-1};
int dcN[]={-2,-1,1,2, 2, 1,-1,-2};
int drQ[]={1,0,-1, 0, 1,1,-1,-1};
int dcQ[]={0,1, 0,-1,-1,1, 1,-1};
int isinside(int row,int col)
{return (row>=0&&row<=7&&col>=0&&col<=7)?1:0;}
int chkP(int,int,int);
int chkR(int,int,int);
int chkB(int,int,int);
int chkQ(int,int,int);
int chkN(int,int,int);
char board[8][9];
int main(void)
{
register int i,j;
int set,out,bkr,bkc,wkr,wkc,bnchk,wnchk;
for(set=0;;){
for(i=out=0;i<8;i++){
gets(board);
for(j=0;j<8;j++){
out+=(board[j]=='.')?1:0;
if(board[j]=='k'){
bkr=i;
bkc=j;
}
if(board[j]=='K'){
wkr=i;
wkc=j;
}
}
}
if(out==64)
break;
gets(board[0]);
printf("Game #%d: ",++set);
bnchk=wnchk=0;
bnchk+=chkP(B,bkr,bkc);
wnchk+=chkP(W,wkr,wkc);
bnchk+=chkR(B,bkr,bkc);
wnchk+=chkR(W,wkr,wkc);
bnchk+=chkB(B,bkr,bkc);
wnchk+=chkB(W,wkr,wkc);
bnchk+=chkQ(B,bkr,bkc);
wnchk+=chkQ(W,wkr,wkc);
bnchk+=chkN(B,bkr,bkc);
wnchk+=chkN(W,wkr,wkc);
if(bnchk>0)
printf("black king is in check.\n");
else if(wnchk>0)
printf("white king is in check.\n");
else
printf("no king is in check.\n");
}
return 0;
}
int chkP(int color,int row,int col)
{
register int i;
int tr,tc;
if(color==B){
for(i=0;i<2;i++){
tr=row+drB;
tc=col+dcB;
if(isinside(tr,tc)&&board[tr][tc]=='P')
return 1;
}
}
else{
for(i=2;i<4;i++){
tr=row+drB;
tc=col+dcB;
if(isinside(tr,tc)&&board[tr][tc]=='p')
return 1;
}
}
return 0;
}
int chkR(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'R':'r';
for(i=0;i<4;i++){
tr=row;
tc=col;
do{
tr+=drR;
tc+=dcR;
}while(isinside(tr,tc)&&board[tr][tc]=='.');
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
int chkB(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'B':'b';
for(i=0;i<4;i++){
tr=row;
tc=col;
do{
tr+=drB[i];
tc+=dcB[i];
}while(isinside(tr,tc)&&board[tr][tc]=='.');
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
int chkQ(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'Q':'q';
for(i=0;i<8;i++){
tr=row;
tc=col;
do{
tr+=drQ[i];
tc+=dcQ[i];
}while(isinside(tr,tc)&&board[tr][tc]=='.');
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
int chkN(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'N':'n';
for(i=0;i<8;i++){
tr=row+drN[i];
tc=col+dcN[i];
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
[/cpp]
[cpp]
#include<stdio.h>
#include<string.h>
enum {B=0,W};
int drR[]={1,0,-1, 0};
int dcR[]={0,1, 0,-1};
int drB[]={ 1,1,-1,-1};
int dcB[]={-1,1, 1,-1};
int drN[]={ 1, 2,2,1,-1,-2,-2,-1};
int dcN[]={-2,-1,1,2, 2, 1,-1,-2};
int drQ[]={1,0,-1, 0, 1,1,-1,-1};
int dcQ[]={0,1, 0,-1,-1,1, 1,-1};
int isinside(int row,int col)
{return (row>=0&&row<=7&&col>=0&&col<=7)?1:0;}
int chkP(int,int,int);
int chkR(int,int,int);
int chkB(int,int,int);
int chkQ(int,int,int);
int chkN(int,int,int);
char board[8][9];
int main(void)
{
register int i,j;
int set,out,bkr,bkc,wkr,wkc,bnchk,wnchk;
for(set=0;;){
for(i=out=0;i<8;i++){
gets(board);
for(j=0;j<8;j++){
out+=(board[j]=='.')?1:0;
if(board[j]=='k'){
bkr=i;
bkc=j;
}
if(board[j]=='K'){
wkr=i;
wkc=j;
}
}
}
if(out==64)
break;
gets(board[0]);
printf("Game #%d: ",++set);
bnchk=wnchk=0;
bnchk+=chkP(B,bkr,bkc);
wnchk+=chkP(W,wkr,wkc);
bnchk+=chkR(B,bkr,bkc);
wnchk+=chkR(W,wkr,wkc);
bnchk+=chkB(B,bkr,bkc);
wnchk+=chkB(W,wkr,wkc);
bnchk+=chkQ(B,bkr,bkc);
wnchk+=chkQ(W,wkr,wkc);
bnchk+=chkN(B,bkr,bkc);
wnchk+=chkN(W,wkr,wkc);
if(bnchk>0)
printf("black king is in check.\n");
else if(wnchk>0)
printf("white king is in check.\n");
else
printf("no king is in check.\n");
}
return 0;
}
int chkP(int color,int row,int col)
{
register int i;
int tr,tc;
if(color==B){
for(i=0;i<2;i++){
tr=row+drB;
tc=col+dcB;
if(isinside(tr,tc)&&board[tr][tc]=='P')
return 1;
}
}
else{
for(i=2;i<4;i++){
tr=row+drB;
tc=col+dcB;
if(isinside(tr,tc)&&board[tr][tc]=='p')
return 1;
}
}
return 0;
}
int chkR(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'R':'r';
for(i=0;i<4;i++){
tr=row;
tc=col;
do{
tr+=drR;
tc+=dcR;
}while(isinside(tr,tc)&&board[tr][tc]=='.');
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
int chkB(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'B':'b';
for(i=0;i<4;i++){
tr=row;
tc=col;
do{
tr+=drB[i];
tc+=dcB[i];
}while(isinside(tr,tc)&&board[tr][tc]=='.');
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
int chkQ(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'Q':'q';
for(i=0;i<8;i++){
tr=row;
tc=col;
do{
tr+=drQ[i];
tc+=dcQ[i];
}while(isinside(tr,tc)&&board[tr][tc]=='.');
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
int chkN(int color,int row,int col)
{
register int i,j;
int tr,tc;
char comp=(color==B)?'N':'n';
for(i=0;i<8;i++){
tr=row+drN[i];
tc=col+dcN[i];
if(isinside(tr,tc)&&board[tr][tc]==comp)
return 1;
}
return 0;
}
[/cpp]
I'm wrong too >< ..
Do I need to consider the move of king? ..
As problem describe, there is no condition as
both the two king in check. Therefore, I don't
consider the move of the king ...
But I got WA ... @@? ...
Is there any special condistion which should be notified? .. thanks for your reply^^ ..
As problem describe, there is no condition as
both the two king in check. Therefore, I don't
consider the move of the king ...
But I got WA ... @@? ...
Is there any special condistion which should be notified? .. thanks for your reply^^ ..
Re: I'm wrong too >< ..
You do not need to consider the move of the king.DemonCris wrote:Do I need to consider the move of king? ..
As problem describe, there is no condition as
both the two king in check. Therefore, I don't
consider the move of the king ...
But I got WA ... @@? ...
Is there any special condistion which should be notified? .. thanks for your reply^^ ..
I think you need to check:
1. input ( I just use scanf("%s",a); )
2. how the chess move (if you are not very careful, it is easy to go wrong)
Good Luck!
try this one
mine failed this case at first:
. . . . . . . .
. . . . . . . .
. . . k . . . .
. . . . . . . .
. B . R . . . .
. . . . . . . .
. . . . . . . .
. K . . . . . .
because i had output for both B and R.
just had to add a couple of break statements and got AC!
. . . . . . . .
. . . . . . . .
. . . k . . . .
. . . . . . . .
. B . R . . . .
. . . . . . . .
. . . . . . . .
. K . . . . . .
because i had output for both B and R.
just had to add a couple of break statements and got AC!
HELP WITH PROBLEM 10196
Dear Programmers:
WHY DO I HAVE A COMPLING ERROR.. PLEASE HELP ME
[pascal]
uses crt;
const
ndx : array [1..8] of integer = (-1,+1,+2,+2,-1,+1,-2,-2);
ndy : array [1..8] of integer = (+2,+2,+1,-1,-2,-2,+1,-1);
kdx : array [1..8] of integer = (+1,-1,+0,+0,+1,+1,-1,-1);
kdy : array [1..8] of integer = (+1,-1,+0,+0,+1,-1,+1,-1);
rdx : array [1..4] of integer = (+1,-1,+0,+0);
rdy : array [1..4] of integer = (+0,+0,+1,-1);
bdx : array [1..4] of integer = (+1,+1,-1,-1);
bdy : array [1..4] of integer = (+1,-1,+1,-1);
var
w,b : array [-1..10,-1..10] of char;
wcheck,bcheck : boolean;
function input:integer;
var i,j : integer;
king: integer;
ch : char;
begin
king := 0;
for i:=1 to 8 do
begin
for j:=1 to 8 do
begin
read(ch);
w[i,j]:='.';
b[i,j]:='.';
if( ch in [ 'a'..'z' ] )then
begin
w[i,j] := ch;
b[i,j] := '*';
if( ch = 'k')then
begin
b[i,j] := '#';
inc(king);
end;
end
else if( ch in [ 'A'..'Z' ] )then
begin
b[i,j] := ch;
w[i,j] := '*';
if( ch = 'K')then
begin
w[i,j] := '#';
inc(king);
end;
end;
end;
readln;
end;
readln;
input:=king;
end;
var
i,j,k : integer;
x,y : integer;
count : integer;
begin
clrscr;
count :=0;
while(input=2)do
begin
inc(count);
bcheck := false;
wcheck := false;
for i:=1 to 8 do
for j:=1 to 8 do
if( w[i,j] = '#' )then
begin
if( w[i+1,j-1] = 'p' ) or
( w[i+1,j+1] = 'p' ) then
wcheck := true;
for k:=1 to 8 do
if( w[i+kdx[k],j+kdy[k]] = 'k' )then
wcheck := true;
for k:=1 to 8 do
if( w[i+ndx[k],j+ndy[k]] = 'n' )then
wcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['r','q'])then
wcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['b','q'])then
wcheck := true;
end;
end;
for i:=1 to 8 do
for j:=1 to 8 do
if( b[i,j] = '#' )then
begin
if( b[i-1,j-1] = 'P' ) or
( b[i-1,j+1] = 'P' ) then
bcheck := true;
for k:=1 to 8 do
if( b[i+kdx[k],j+kdy[k]] = 'K')then
bcheck := true;
for k:=1 to 8 do
if( b[i+ndx[k],j+ndy[k]] = 'N')then
bcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['R','Q'])then
bcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['B','Q'])then
bcheck := true;
end;
end;
write('Game #',count,': ');
if( bcheck )then writeln('black king is in check.')
else if( wcheck )then writeln('white king is in check.')
else writeln('no king is in check.');
end;
end.
[/pascal]
WHY DO I HAVE A COMPLING ERROR.. PLEASE HELP ME
[pascal]
uses crt;
const
ndx : array [1..8] of integer = (-1,+1,+2,+2,-1,+1,-2,-2);
ndy : array [1..8] of integer = (+2,+2,+1,-1,-2,-2,+1,-1);
kdx : array [1..8] of integer = (+1,-1,+0,+0,+1,+1,-1,-1);
kdy : array [1..8] of integer = (+1,-1,+0,+0,+1,-1,+1,-1);
rdx : array [1..4] of integer = (+1,-1,+0,+0);
rdy : array [1..4] of integer = (+0,+0,+1,-1);
bdx : array [1..4] of integer = (+1,+1,-1,-1);
bdy : array [1..4] of integer = (+1,-1,+1,-1);
var
w,b : array [-1..10,-1..10] of char;
wcheck,bcheck : boolean;
function input:integer;
var i,j : integer;
king: integer;
ch : char;
begin
king := 0;
for i:=1 to 8 do
begin
for j:=1 to 8 do
begin
read(ch);
w[i,j]:='.';
b[i,j]:='.';
if( ch in [ 'a'..'z' ] )then
begin
w[i,j] := ch;
b[i,j] := '*';
if( ch = 'k')then
begin
b[i,j] := '#';
inc(king);
end;
end
else if( ch in [ 'A'..'Z' ] )then
begin
b[i,j] := ch;
w[i,j] := '*';
if( ch = 'K')then
begin
w[i,j] := '#';
inc(king);
end;
end;
end;
readln;
end;
readln;
input:=king;
end;
var
i,j,k : integer;
x,y : integer;
count : integer;
begin
clrscr;
count :=0;
while(input=2)do
begin
inc(count);
bcheck := false;
wcheck := false;
for i:=1 to 8 do
for j:=1 to 8 do
if( w[i,j] = '#' )then
begin
if( w[i+1,j-1] = 'p' ) or
( w[i+1,j+1] = 'p' ) then
wcheck := true;
for k:=1 to 8 do
if( w[i+kdx[k],j+kdy[k]] = 'k' )then
wcheck := true;
for k:=1 to 8 do
if( w[i+ndx[k],j+ndy[k]] = 'n' )then
wcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['r','q'])then
wcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['b','q'])then
wcheck := true;
end;
end;
for i:=1 to 8 do
for j:=1 to 8 do
if( b[i,j] = '#' )then
begin
if( b[i-1,j-1] = 'P' ) or
( b[i-1,j+1] = 'P' ) then
bcheck := true;
for k:=1 to 8 do
if( b[i+kdx[k],j+kdy[k]] = 'K')then
bcheck := true;
for k:=1 to 8 do
if( b[i+ndx[k],j+ndy[k]] = 'N')then
bcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['R','Q'])then
bcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['B','Q'])then
bcheck := true;
end;
end;
write('Game #',count,': ');
if( bcheck )then writeln('black king is in check.')
else if( wcheck )then writeln('white king is in check.')
else writeln('no king is in check.');
end;
end.
[/pascal]
HELP WITH PROBLEM 10196
Dear Programmers:
WHY DO I HAVE A COMPLING ERROR.. PLEASE HELP ME
[pascal]
uses crt;
const
ndx : array [1..8] of integer = (-1,+1,+2,+2,-1,+1,-2,-2);
ndy : array [1..8] of integer = (+2,+2,+1,-1,-2,-2,+1,-1);
kdx : array [1..8] of integer = (+1,-1,+0,+0,+1,+1,-1,-1);
kdy : array [1..8] of integer = (+1,-1,+0,+0,+1,-1,+1,-1);
rdx : array [1..4] of integer = (+1,-1,+0,+0);
rdy : array [1..4] of integer = (+0,+0,+1,-1);
bdx : array [1..4] of integer = (+1,+1,-1,-1);
bdy : array [1..4] of integer = (+1,-1,+1,-1);
var
w,b : array [-1..10,-1..10] of char;
wcheck,bcheck : boolean;
function input:integer;
var i,j : integer;
king: integer;
ch : char;
begin
king := 0;
for i:=1 to 8 do
begin
for j:=1 to 8 do
begin
read(ch);
w[i,j]:='.';
b[i,j]:='.';
if( ch in [ 'a'..'z' ] )then
begin
w[i,j] := ch;
b[i,j] := '*';
if( ch = 'k')then
begin
b[i,j] := '#';
inc(king);
end;
end
else if( ch in [ 'A'..'Z' ] )then
begin
b[i,j] := ch;
w[i,j] := '*';
if( ch = 'K')then
begin
w[i,j] := '#';
inc(king);
end;
end;
end;
readln;
end;
readln;
input:=king;
end;
var
i,j,k : integer;
x,y : integer;
count : integer;
begin
clrscr;
count :=0;
while(input=2)do
begin
inc(count);
bcheck := false;
wcheck := false;
for i:=1 to 8 do
for j:=1 to 8 do
if( w[i,j] = '#' )then
begin
if( w[i+1,j-1] = 'p' ) or
( w[i+1,j+1] = 'p' ) then
wcheck := true;
for k:=1 to 8 do
if( w[i+kdx[k],j+kdy[k]] = 'k' )then
wcheck := true;
for k:=1 to 8 do
if( w[i+ndx[k],j+ndy[k]] = 'n' )then
wcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['r','q'])then
wcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['b','q'])then
wcheck := true;
end;
end;
for i:=1 to 8 do
for j:=1 to 8 do
if( b[i,j] = '#' )then
begin
if( b[i-1,j-1] = 'P' ) or
( b[i-1,j+1] = 'P' ) then
bcheck := true;
for k:=1 to 8 do
if( b[i+kdx[k],j+kdy[k]] = 'K')then
bcheck := true;
for k:=1 to 8 do
if( b[i+ndx[k],j+ndy[k]] = 'N')then
bcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['R','Q'])then
bcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['B','Q'])then
bcheck := true;
end;
end;
write('Game #',count,': ');
if( bcheck )then writeln('black king is in check.')
else if( wcheck )then writeln('white king is in check.')
else writeln('no king is in check.');
end;
end.
[/pascal]
WHY DO I HAVE A COMPLING ERROR.. PLEASE HELP ME
[pascal]
uses crt;
const
ndx : array [1..8] of integer = (-1,+1,+2,+2,-1,+1,-2,-2);
ndy : array [1..8] of integer = (+2,+2,+1,-1,-2,-2,+1,-1);
kdx : array [1..8] of integer = (+1,-1,+0,+0,+1,+1,-1,-1);
kdy : array [1..8] of integer = (+1,-1,+0,+0,+1,-1,+1,-1);
rdx : array [1..4] of integer = (+1,-1,+0,+0);
rdy : array [1..4] of integer = (+0,+0,+1,-1);
bdx : array [1..4] of integer = (+1,+1,-1,-1);
bdy : array [1..4] of integer = (+1,-1,+1,-1);
var
w,b : array [-1..10,-1..10] of char;
wcheck,bcheck : boolean;
function input:integer;
var i,j : integer;
king: integer;
ch : char;
begin
king := 0;
for i:=1 to 8 do
begin
for j:=1 to 8 do
begin
read(ch);
w[i,j]:='.';
b[i,j]:='.';
if( ch in [ 'a'..'z' ] )then
begin
w[i,j] := ch;
b[i,j] := '*';
if( ch = 'k')then
begin
b[i,j] := '#';
inc(king);
end;
end
else if( ch in [ 'A'..'Z' ] )then
begin
b[i,j] := ch;
w[i,j] := '*';
if( ch = 'K')then
begin
w[i,j] := '#';
inc(king);
end;
end;
end;
readln;
end;
readln;
input:=king;
end;
var
i,j,k : integer;
x,y : integer;
count : integer;
begin
clrscr;
count :=0;
while(input=2)do
begin
inc(count);
bcheck := false;
wcheck := false;
for i:=1 to 8 do
for j:=1 to 8 do
if( w[i,j] = '#' )then
begin
if( w[i+1,j-1] = 'p' ) or
( w[i+1,j+1] = 'p' ) then
wcheck := true;
for k:=1 to 8 do
if( w[i+kdx[k],j+kdy[k]] = 'k' )then
wcheck := true;
for k:=1 to 8 do
if( w[i+ndx[k],j+ndy[k]] = 'n' )then
wcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['r','q'])then
wcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (w[x,y]<>'.');
if( w[x,y] in ['b','q'])then
wcheck := true;
end;
end;
for i:=1 to 8 do
for j:=1 to 8 do
if( b[i,j] = '#' )then
begin
if( b[i-1,j-1] = 'P' ) or
( b[i-1,j+1] = 'P' ) then
bcheck := true;
for k:=1 to 8 do
if( b[i+kdx[k],j+kdy[k]] = 'K')then
bcheck := true;
for k:=1 to 8 do
if( b[i+ndx[k],j+ndy[k]] = 'N')then
bcheck := true;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+rdx[k]; y:=y+rdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['R','Q'])then
bcheck := true;
end;
for k:=1 to 4 do
begin
x := i; y := j;
repeat x:=x+bdx[k]; y:=y+bdx[k];
until (b[x,y]<>'.');
if( b[x,y] in ['B','Q'])then
bcheck := true;
end;
end;
write('Game #',count,': ');
if( bcheck )then writeln('black king is in check.')
else if( wcheck )then writeln('white king is in check.')
else writeln('no king is in check.');
end;
end.
[/pascal]
10196 - CHECK THE CHECK
Dear EVERYONE!
I'm am not sure how to send my programs into the ACM grader...
Here is my program from MINESWEEPER , ID # 10189
Please Help me Find out what is Wrong!
its keeps saying Compiner Error
[c]
#include<stdio.h>
int m,n;
char field[100][100]={0};
int map [100][100]={0};
main()
{
int i,j;
char ch;
scanf("%d%d",&m,&n);
while(( m != 0) && ( n!=0 ))
{
//RESET//
for(i=0;i<100;i++)
for(j=0;j<100;j++)
{field[j]=0;
map[j]=0;}
//INPUT//
for(i=1;i<=m;i++)
{ scanf("%c",&ch);
for(j=1;j<=n;j++)
scanf("%c",&field[j]);}
//WORK//
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(field[j] == '*')
{ map[i+1][j+0] ++;
map[i+1][j+1] ++;
map[i+1][j-1] ++;
map[i+0][j+1] ++;
map[i+0][j-1] ++;
map[i-1][j+0] ++;
map[i-1][j+1] ++;
map[i-1][j-1] ++;}
//OUTPUT//
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
if(field[j] == '*') printf("*");
else printf("%d",map[j]);
printf("\n");}
scanf("%d%d",&m,&n);
}
}[/c]
HELP! AHHHHHHHH!![:evil:](./images/smilies/icon_evil.gif)
I'm am not sure how to send my programs into the ACM grader...
Here is my program from MINESWEEPER , ID # 10189
Please Help me Find out what is Wrong!
its keeps saying Compiner Error
![:o](./images/smilies/icon_eek.gif)
[c]
#include<stdio.h>
int m,n;
char field[100][100]={0};
int map [100][100]={0};
main()
{
int i,j;
char ch;
scanf("%d%d",&m,&n);
while(( m != 0) && ( n!=0 ))
{
//RESET//
for(i=0;i<100;i++)
for(j=0;j<100;j++)
{field[j]=0;
map[j]=0;}
//INPUT//
for(i=1;i<=m;i++)
{ scanf("%c",&ch);
for(j=1;j<=n;j++)
scanf("%c",&field[j]);}
//WORK//
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(field[j] == '*')
{ map[i+1][j+0] ++;
map[i+1][j+1] ++;
map[i+1][j-1] ++;
map[i+0][j+1] ++;
map[i+0][j-1] ++;
map[i-1][j+0] ++;
map[i-1][j+1] ++;
map[i-1][j-1] ++;}
//OUTPUT//
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
if(field[j] == '*') printf("*");
else printf("%d",map[j]);
printf("\n");}
scanf("%d%d",&m,&n);
}
}[/c]
HELP! AHHHHHHHH!
![:evil:](./images/smilies/icon_evil.gif)
Yes. Cut the "crt" part and you'll no longer get CE (but you'll get WA)
![:D](./images/smilies/icon_biggrin.gif)
![:)](./images/smilies/icon_smile.gif)
![:D](./images/smilies/icon_biggrin.gif)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- Experienced poster
- Posts: 147
- Joined: Fri Jun 13, 2003 10:46 pm
10196 : please give me some sample input and output
can any body give me some samples input output
thanx
thanx
-
- New poster
- Posts: 38
- Joined: Thu Dec 11, 2003 3:40 pm
- Location: Bangalore
10196 : check the check WA.. Please explain the logic..
What could be wrong.. I get WA even when i have checked for all the conditions i can think of.. I do not check for kings move because both kings can never be in a check... Please tell me a case where my program fails... or if any of you have a different approach...
Thx
Aakash
[cpp]
# include<iostream.h>
char a[10][10];
int bkx,bky,wkx,wky;
int i,j,x,y;
int main()
{
long long nt=0;
while(1)
{
bkx=bky=wkx=wky=-1;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
cin>>a[j];
if(a[j]=='k') {bkx=i;bky=j;}
if(a[j]=='K') {wkx=i;wky=j;}
}
}
if(bkx==-1 && bky==-1 && wkx==-1 && wky==-1) return 1;
cout<<"Game #"<<++nt<<": ";
if(bkx<7 && bky>0 && a[bkx+1][bky-1]=='P') {cout<<"black king is in check.\n";goto end;}
if(bkx<7 && bky<7 && a[bkx+1][bky+1]=='P') {cout<<"black king is in check.\n";goto end;}
if(bkx+2<8 && bky+1<8 && a[bkx+2][bky+1]=='N') {cout<<"black king is in check.\n";goto end;}
if(bkx+2<8 && bky-1>=0 && a[bkx+2][bky-1]=='N') {cout<<"black king is in check.\n";goto end;}
if(bkx-2>=0 && bky+1<8 && a[bkx-2][bky+1]=='N') {cout<<"black king is in check.\n";goto end;}
if(bkx-2>=0 && bky-1>=0 && a[bkx-2][bky-1]=='N') {cout<<"black king is in check.\n";goto end;}
if(bkx+1<8 && bky+2<8 && a[bkx+1][bky+2]=='N') {cout<<"black king is in check.\n";goto end;}
if(bkx+1<8 && bky-2>=0 && a[bkx+1][bky-2]=='N') {cout<<"black king is in check.\n";goto end;}
if(bkx-1>=0 && bky+2<8 && a[bkx-1][bky+2]=='N') {cout<<"black king is in check.\n";goto end;}
if(bkx-1>=0 && bky-2>=0 && a[bkx-1][bky-2]=='N') {cout<<"black king is in check.\n";goto end;}
x=bkx;y=bky;
while(1)
{
x++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='R' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
x=bkx;y=bky;
while(1)
{
x--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='R' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
x=bkx;y=bky;
while(1)
{
y++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='R' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
x=bkx;y=bky;
while(1)
{
y--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='R' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
x=bkx;y=bky;
while(1)
{
x++;y++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='B' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
x=bkx;y=bky;
while(1)
{
x++;y--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='B' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
x=bkx;y=bky;
while(1)
{
x--;y++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='B' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
x=bkx;y=bky;
while(1)
{
x--;y--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='a' && a[x][y]<='z') break;
if(a[x][y]=='B' || a[x][y]=='Q') {cout<<"black king is in check.\n";goto end;}
}
/////////////////////////////
if(wkx>0 && wky>0 && a[wkx-1][wky-1]=='p') {cout<<"white king is in check.\n";goto end;}
if(wkx>0 && wky<7 && a[wkx-1][wky+1]=='p') {cout<<"white king is in check.\n";goto end;}
if(wkx+2<8 && wky+1<8 && a[wkx+2][wky+1]=='n') {cout<<"white king is in check.\n";goto end;}
if(wkx+2<8 && wky-1>=0 && a[wkx+2][wky-1]=='n') {cout<<"white king is in check.\n";goto end;}
if(wkx-2>=0 && wky+1<8 && a[wkx-2][wky+1]=='n') {cout<<"white king is in check.\n";goto end;}
if(wkx-2>=0 && wky-1>=0 && a[wkx-2][wky-1]=='n') {cout<<"white king is in check.\n";goto end;}
if(wkx+1<8 && wky+2<8 && a[wkx+1][wky+2]=='n') {cout<<"white king is in check.\n";goto end;}
if(wkx+1<8 && wky-2>=0 && a[wkx+1][wky-2]=='n') {cout<<"white king is in check.\n";goto end;}
if(wkx-1>=0 && wky+2<8 && a[wkx-1][wky+2]=='n') {cout<<"white king is in check.\n";goto end;}
if(wkx-1>=0 && wky-2>=0 && a[wkx-1][wky-2]=='n') {cout<<"white king is in check.\n";goto end;}
x=wkx;y=wky;
while(1)
{
x++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='r' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
x=wkx;y=wky;
while(1)
{
x--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='r' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
x=wkx;y=wky;
while(1)
{
y++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='r' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
x=wkx;y=wky;
while(1)
{
y--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='r' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
x=wkx;y=wky;
while(1)
{
x++;y++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='b' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
x=wkx;y=wky;
while(1)
{
x++;y--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='b' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
x=wkx;y=wky;
while(1)
{
x--;y++;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='b' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
x=wkx;y=wky;
while(1)
{
x--;y--;
if(x>=8) break;
if(y>=8) break;
if(x<0) break;
if(y<0) break;
if(a[x][y]>='A' && a[x][y]<='Z') break;
if(a[x][y]=='b' || a[x][y]=='q') {cout<<"white king is in check.\n";goto end;}
}
///////////////////////////////
cout<<"no king is in check.\n";
end:
x=bkx;
}
}
[/cpp]
...I was born to code...
10196 > Critical input/output PLZ!!.
Greetings!.
I've been singing and dancing with this problem, and still can't figure out what's wrong with it.
I've tried this input:
and works great.
But I got WA!!![:cry:](./images/smilies/icon_cry.gif)
I'm tired of WAs...
I read in a post I don't need to consider to move the Kings, as I already did in my problem, so, what could be wrong?.
Any idea of a critical input/output for this problem?.
Thanks in advance.
_.B._
http://online-judge.uva.es/cgi-bin/Onli ... Info:42085
I've been singing and dancing with this problem, and still can't figure out what's wrong with it.
I've tried this input:
Code: Select all
N......N
........
.k......
........
........
........
........
N......N
n......n
........
........
........
........
......K.
........
n......n
Q......Q
........
........
........
........
........
......k.
Q......Q
q......q
........
........
........
........
........
.K......
q......q
. . . . . . . .
. . . . . . . .
. . . k . . . .
. . . . . . . .
. B . R . . . .
. . . . . . . .
. . . . . . . .
. K . . . . . .
..k.....
ppp.pppp
........
.R...B..
........
........
PPPPPPPP
K.......
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
rnbqk.nr
ppp..ppp
....p...
...p....
.bPP....
.....N..
PP..PPPP
RNBQKB.R
........
........
........
........
........
........
........
........
But I got WA!!
![:cry:](./images/smilies/icon_cry.gif)
I'm tired of WAs...
I read in a post I don't need to consider to move the Kings, as I already did in my problem, so, what could be wrong?.
Any idea of a critical input/output for this problem?.
Thanks in advance.
_.B._
http://online-judge.uva.es/cgi-bin/Onli ... Info:42085
10196 WA... very confused.
I have no idea of what the program must output if there is a white king adyacent to a black king....who hack?
But for the others case I have make the things well...or that what I think...
Here is my code:
[c]
#include <stdio.h>
int main()
{
int i,x,j,k; /*counters*/
/* i=fila x=columnas*/
int s=1,end=0; /*numero de tablero*/
char board[10][10];
empieza:
end=0,i=x=1;
while(i<=8)
{
scanf("%c", &board[x]);
if (board[x]=='.')
end++;
if (board[x]=='\n')
{
if (end==64)
return 0;
i++;
x=1;
}
else
x++;
}
for (i=1; i<=8; i++)
for (x=1; x<=8; x++)
{
if (board[x]=='K') /*SI HAY KING BLANCO */
{
if (board[i+1][x+1]=='p' || board[i+1][x-1]=='p') /*
But for the others case I have make the things well...or that what I think...
Here is my code:
[c]
#include <stdio.h>
int main()
{
int i,x,j,k; /*counters*/
/* i=fila x=columnas*/
int s=1,end=0; /*numero de tablero*/
char board[10][10];
empieza:
end=0,i=x=1;
while(i<=8)
{
scanf("%c", &board[x]);
if (board[x]=='.')
end++;
if (board[x]=='\n')
{
if (end==64)
return 0;
i++;
x=1;
}
else
x++;
}
for (i=1; i<=8; i++)
for (x=1; x<=8; x++)
{
if (board[x]=='K') /*SI HAY KING BLANCO */
{
if (board[i+1][x+1]=='p' || board[i+1][x-1]=='p') /*