10196 - Check The Check
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
On the sample input:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 7
at java.lang.String.charAt(Unknown Source)
at Main.main(Main.java:452)
Use the code blocks when posting code.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 7
at java.lang.String.charAt(Unknown Source)
at Main.main(Main.java:452)
Use the code blocks when posting code.
Check input and AC output for thousands of problems on uDebug!
Re: 10196 - Check The Check
Sir but i checked the sample input for many times in java compiler.......besides i cannot understand if ""Each board will consist of 8 lines of 8 characters each"" is written in the question then
how it becomes "Run Time Error"...
please Sir make me Understand..........![:(](./images/smilies/icon_frown.gif)
how it becomes "Run Time Error"...
please Sir make me Understand..........
![:(](./images/smilies/icon_frown.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
There will be an empty line between each pair of board configurations.
https://ideone.com/JIGeEz
https://ideone.com/JIGeEz
Check input and AC output for thousands of problems on uDebug!
Re: 10196 - Check The Check
thanks GURU ...
i edited my code but i got now
"Wrong Answer"!!!!!!!
can you please give me some critical input output....![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
"Wrong Answer"!!!!!!!
can you please give me some critical input output....
![:)](./images/smilies/icon_smile.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
Use class Main.
http://uva.onlinejudge.org/index.php?op ... &Itemid=30
Use the code blocks when posting code. Look for the "Code" button in the text box.
http://uva.onlinejudge.org/index.php?op ... &Itemid=30
Use the code blocks when posting code. Look for the "Code" button in the text box.
Check input and AC output for thousands of problems on uDebug!
Re: 10196 - Check The Check
sorry sir :@brain fry
when i sumitted i wrote Main
but its Wrong Ansrwer
can u please give me some critical inputs outputs![:)](./images/smilies/icon_smile.gif)
when i sumitted i wrote Main
but its Wrong Ansrwer
can u please give me some critical inputs outputs
![:)](./images/smilies/icon_smile.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re:
CodeMaker wrote:Here i give you some input output, you can check with them...
intputs:
outputs: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 ........ ........ ........ ........ ........ ........ ........ ........
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.
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
Here is your code inside code blocks
Do you agree that's easier to read? You can click one button to select all and then copy it, instead of having to scroll through 529 lines. It will also preserve the indentation.
Always post the code you'd submit.
Code: Select all
import java.io.*;
import java.util.*;
public class Main{
static boolean Blacking(int c , int t , String [] [] y){
int counter = 0;
int first = c,second = t;
int done = 0;
while(second<8)
{
if(y[first][second].equals("R") || y[first][second].equals("Q"))
{
done = 1;
break;
}
second++;
}
first = c;
second = t;
while(second>=0 && done ==0)
{
if(y[first][second].equals("R")||y[first][second].equals("Q"))
{
done = 1;
break;
}
second--;
}
first = c;
second = t;
while(first<8 && done ==0)
{
if(y[first][second].equals("R")||y[first][second].equals("Q"))
{
done = 1;
break;
}
first++;
}
first = c;
second = t;
while(first>=0 && done ==0)
{
if(y[first][second].equals("R")||y[first][second].equals("Q"))
{
done = 1;
break;
}
first--;
}
first = c;
second = t;
while(second<8 && first<8 && done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("R"))
{
done = 1;
break;
}
first++;
second++;
}
first = c;
second = t;
while(second>=0 && first<8&& done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("B"))
{
done = 1;
break;
}
first++;
second--;
}
first = c;
second = t;
while(second>=0 && first>=0 && done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("B"))
{
done = 1;
break;
}
first--;
second--;
}
first = c;
second = t;
while(second<8 && first>=0 && done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("B"))
{
done = 1;
break;
}
first--;
second++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && done ==0 && counter<2)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
first += 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
first += 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
first -= 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
first -= 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
first++;
second +=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
first++;
second -=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("P"))
{
done = 1;
break;
}
first--;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("P"))
{
done = 1;
break;
}
first--;
second++;
counter++;
}
if(done==1)
{
return true;
}
return false;
}
static boolean WhiteKing(int c , int t , String [] [] y){
int counter = 0;
int done = 0;
int first = c,second = t;
while(second<8 && done==0)
{
if(y[first][second].equals("r") || y[first][second].equals("q"))
{
done = 1;
break;
}
second++;
}
first = c;
second = t;
while(second>=0 && done==0)
{
if(y[first][second].equals("r")||y[first][second].equals("q"))
{
done = 1;
break;
}
second--;
}
first = c;
second = t;
while(first<8 && done ==0)
{
if(y[first][second].equals("r")||y[first][second].equals("q"))
{
done = 1;
break;
}
first++;
}
first = c;
second = t;
while(first>=0 && done==0)
{
if(y[first][second].equals("r")||y[first][second].equals("q"))
{
done = 1;
break;
}
first--;
}
first = c;
second = t;
while(second<8 && first<8 && done==0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
first++;
second++;
}
first = c;
second = t;
while(second>=0 && first<8 && done ==0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
first++;
second--;
}
first = c;
second = t;
while(second>=0 && first>=0 && done ==0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
first--;
second--;
}
first = c;
second = t;
while(second<8 && first>=0 && done == 0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
first--;
second++;
}
first = c;
second = t;
while(first<8 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
first += 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
first += 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && done ==0 && counter<2)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
first -= 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && done ==0 && counter<2)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
first -= 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
first++;
second +=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
first++;
second -=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("p"))
{
done = 1;
break;
}
first ++;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && counter<2 && done == 0)
{
if(y[first][second].equals("p"))
{
done = 1;
break;
}
first ++;
second++;
counter++;
}
if(done==1)
{
return true;
}
return false;
}
public static void main(String [] args)throws IOException{
final BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
PrintWriter z = new PrintWriter(System.out);
String [] [] x = new String[8][8];
int i = 1;
String line;
while((line = k.readLine()) != null)
{
boolean B = false,W = false;
String [][] y = new String [8][8];
int c = 0;
int r1 = 7;
while(c<8)
{
int r2 = 0;
int t = 0;
String s = "";
if(c==0)
{
s = line;
}
else
{
s = k.readLine();
}
while(t<8)
{
y[r1][r2] = ""+s.charAt(t);
r2++;
t++;
}
r1--;
c++;
}
c = 0;
int u = 0;
while(c<8)
{
int t = 0;
while(t<8)
{
if(!(y[c][t].equals(".")))
{
u = 1;
break;
}
t++;
}
c++;
}
if(u==0)
{
break;
}
else
{
k.readLine();
c = 0;
while(c<8)
{
int t = 0;
while(t<8)
{
if(y[c][t].equals("K"))
{
W = WhiteKing(c,t,y);
if(W)
{
break;
}
}
else if(y[c][t].equals("k"))
{
B = Blacking(c,t,y);
if(B)
{
break;
}
}
t++;
}
c++;
}
if(W)
{
z.println("Game #"+i+": white king is in check.");
i++;
}
else if(B)
{
z.println("Game #"+i+": black king is in check.");
i++;
}
else
{
z.println("Game #"+i+": no king is in check.");
i++;
}
}
}
z.flush();
}
}
Always post the code you'd submit.
Check input and AC output for thousands of problems on uDebug!
Re: 10196 - Check The Check
:@ guru brainfry
i am extremely sorry....![:(](./images/smilies/icon_frown.gif)
i didnt understood what you were talking about...
Now i understand...![:D](./images/smilies/icon_biggrin.gif)
and thanks for giving me critical inputs outputs...![:D](./images/smilies/icon_biggrin.gif)
i am extremely sorry....
![:(](./images/smilies/icon_frown.gif)
i didnt understood what you were talking about...
Now i understand...
![:D](./images/smilies/icon_biggrin.gif)
and thanks for giving me critical inputs outputs...
![:D](./images/smilies/icon_biggrin.gif)
Re: 10196 - Check The Check
@Brain fry i tried your all inputs/outputs they were match in my code but still WRONG ANSWER
![:cry:](./images/smilies/icon_cry.gif)
Code: Select all
import java.io.*;
import java.util.*;
public class Main{
static boolean Blacking(int c , int t , String [] [] y){
int counter = 0;
int first = c,second = t;
int done = 0;
while(second<8)
{
if(y[first][second].equals("R") || y[first][second].equals("Q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
second++;
}
first = c;
second = t;
while(second>=0 && done ==0)
{
if(y[first][second].equals("R")||y[first][second].equals("Q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
second--;
}
first = c;
second = t;
while(first<8 && done ==0)
{
if(y[first][second].equals("R")||y[first][second].equals("Q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first++;
}
first = c;
second = t;
while(first>=0 && done ==0)
{
if(y[first][second].equals("R")||y[first][second].equals("Q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first--;
}
first = c;
second = t;
while(second<8 && first<8 && done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("B"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first++;
second++;
}
first = c;
second = t;
while(second>=0 && first<8&& done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("B"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first++;
second--;
}
first = c;
second = t;
while(second>=0 && first>=0 && done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("B"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first--;
second--;
}
first = c;
second = t;
while(second<8 && first>=0 && done ==0)
{
if(y[first][second].equals("Q")||y[first][second].equals("B"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first--;
second++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && done ==0 && counter<2)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first += 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first += 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first -= 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first -= 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first++;
second +=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first--;
second -=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first--;
second +=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("N"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first++;
second -=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("P"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first--;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("P"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("k")))
{
break;
}
first--;
second++;
counter++;
}
if(done==1)
{
return true;
}
return false;
}
static boolean WhiteKing(int c , int t , String [] [] y){
int counter = 0;
int done = 0;
int first = c,second = t;
while(second<8 && done==0)
{
if(y[first][second].equals("r") || y[first][second].equals("q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
second++;
}
first = c;
second = t;
while(second>=0 && done==0)
{
if(y[first][second].equals("r")||y[first][second].equals("q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
second--;
}
first = c;
second = t;
while(first<8 && done ==0)
{
if(y[first][second].equals("r")||y[first][second].equals("q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first++;
}
first = c;
second = t;
while(first>=0 && done==0)
{
if(y[first][second].equals("r")||y[first][second].equals("q"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first--;
}
first = c;
second = t;
while(second<8 && first<8 && done==0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first++;
second++;
}
first = c;
second = t;
while(second>=0 && first<8 && done ==0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first++;
second--;
}
first = c;
second = t;
while(second>=0 && first>=0 && done ==0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first--;
second--;
}
first = c;
second = t;
while(second<8 && first>=0 && done == 0)
{
if(y[first][second].equals("q")||y[first][second].equals("b"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first--;
second++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && done ==0 && counter<2)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first += 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first += 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first -= 2;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first -= 2;
second++;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first++;
second +=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first--;
second -=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first>=0 && second<8 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first--;
second +=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("n"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first++;
second -=2;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second>=0 && counter<2 && done==0)
{
if(y[first][second].equals("p"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first ++;
second--;
counter++;
}
first = c;
second = t;
counter = 0;
while(first<8 && second<8 && counter<2 && done == 0)
{
if(y[first][second].equals("p"))
{
done = 1;
break;
}
else if(!(y[first][second].equals(".")) && !(y[first][second].equals("K")))
{
break;
}
first ++;
second++;
counter++;
}
if(done==1)
{
return true;
}
return false;
}
public static void main(String [] args)throws IOException{
final BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
PrintWriter z = new PrintWriter(System.out);
String [] [] cheq = {{".",".",".",".",".",".",".","."},{".",".",".",".",".",".",".","."},{".",".",".",".",".",".",".","."},{".",".",".",".",".",".",".","."},{".",".",".",".",".",".",".","."},{".",".",".",".",".",".",".","."},{".",".",".",".",".",".",".","."},{".",".",".",".",".",".",".","."}};
int i = 1;
String line;
while((line = k.readLine()) != null)
{
String [][] y = new String [8][8];
int white = 0,black = 0;
boolean b = false;
for(int c = 0;c<8;c++)
{
y[7][c] = line.charAt(c)+"";
}
for(int c = 6;c>=0;c--)
{
String s = k.readLine();
for(int d = 0;d<8;d++)
{
y[c][d] = ""+s.charAt(d);
}
}
if(Arrays.deepEquals(cheq,y))
{
break;
}
else
{
k.readLine();
for(int c = 7;c>=0;c--)
{
for(int d = 0;d<8;d++)
{
if(y[c][d].equals("K"))
{
b = WhiteKing(c,d,y);
if(b)
{
white = 1;
break;
}
}
else if(y[c][d].equals("k"))
{
b = Blacking(c,d,y);
if(b)
{
black = 1;
break;
}
}
}
if(b)
{
break;
}
}
if(b && black==1)
{
z.println("Game #"+i+": black king is in check.");
}
else if(b && white==1)
{
z.println("Game #"+i+": white king is in check.");
}
else
{
z.println("Game #"+i+": no king is in check.");
}
i++;
}
}
z.flush();
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
Try input:
Code: Select all
.......K
........
........
........
.....n..
k.......
........
........
........
........
........
........
........
........
........
........
Check input and AC output for thousands of problems on uDebug!
Re: 10196 - Check The Check
Hi I have tested my code with all cases provide in this forum. But I am getting WA.
Please help me to find out what I am doing wrong. Here is my code -
Thanks in advance.
Please help me to find out what I am doing wrong. Here is my code -
Code: Select all
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <valarray>
#include <functional>
using namespace std;
#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1000000001
typedef long long Long;
//typedef __int64 Long;
#define pi (2*acos(0))
#define eps 1e-9
#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
#define pb(x) push_back(x)
#define present(m,s) (m.find(s)!=m.end())
typedef pair<int,int> ii;
char BUFFER[100000 + 5];
bool readn(int &n) { return scanf("%d",&n) == 1; }
//bool readl(Long &n) { return scanf("%I64d",&n) == 1; }
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#define maxn 10
char g[maxn][maxn];
bool valid(int i, int j){
if(i < 0 || j < 0 || i >= 8 || j >= 8) return false;
return true;
}
bool rook_queen(int x, int y, int (*f)(int)){
int i;
// check forward
fo(i,1,8-y){
if(g[x][y+i] == f('r') || g[x][y+i] == f('q')) return true;
if(g[x][y+i] != '.') break;
}
// check backward
fo(i,1,y){
if(g[x][y-i] == f('r') || g[x][y-i] == f('q')) return true;
if(g[x][y-i] != '.') break;
}
// check upward
fo(i,1,x){
if(g[x-i][y] == f('r') || g[x-i][y] == f('q')) return true;
if(g[x-i][y] != '.') break;
}
// check downward
fo(i,1,8-x){
if(g[x+i][y] == 'r' || g[x+i][y] == 'q') return true;
if(g[x+i][y] != '.') break;
}
return false;
}
bool bishop_queen(int x, int y, int (*f)(int)){
int i;
// check toward north east corner
fo(i,1,min(x,8-y)){
if(g[x-i][y+i] == f('b') || g[x-i][y+i] == f('q')) return true;
if(g[x-i][y+i] != '.') break;
}
// check toward south east corner
fo(i,1,min(8-x,8-y)){
if(g[x+i][y+i] == f('b') || g[x+i][y+i] == f('q')) return true;
if(g[x+i][y+i] != '.') break;
}
// check toward south west corner
fo(i,1,min(8-x,y)){
if(g[x+i][y-i] == f('b') || g[x+i][y-i] == f('q')) return true;
if(g[x+i][y-i] == '.') break;
}
// check toward north west corner
fo(i,1,min(x,y)){
if(g[x-i][y-i] == f('b') ||g[x-i][y-i] == f('q')) return true;
if(g[x-i][y-i] != '.') break;
}
return false;
}
#define row 0
#define col 1
int dir[][8] = {
1,2,2,1,-1,-2,-2,-1,
2,1,-1,-2,-2,-1,1,2
};
bool knight(int x, int y, int (*f)(int)){
int i;
fo(i, 0,8){
if(valid(x+dir[row][i],y+dir[col][i]) && g[x+dir[row][i]][y+dir[col][i]] == f('n')) return true;
}
return false;
}
bool white_king_checked(int x, int y){
if(valid(x-1,y-1) && g[x-1][y-1] == 'p') return true;
if(valid(x-1,y+1) && g[x-1][y+1] == 'p') return true;
if(knight(x,y,tolower)) return true;
if(rook_queen(x,y,tolower)) return true;
if(bishop_queen(x,y,tolower)) return true;
return false;
}
bool black_king_checked(int x, int y){
if(valid(x+1,y-1) && g[x+1][y-1] == 'P') return true;
if(valid(x+1,y+1) && g[x+1][y+1] == 'P') return true;
if(knight(x,y,toupper)) return true;
if(rook_queen(x,y,toupper)) return true;
if(bishop_queen(x,y,toupper)) return true;
return false;
}
int main()
{
#ifdef localhost
freopen("G:\\test.in","r",stdin);
//freopen("G:\\test.out","w",stdout);
#endif
int i,j, kase = 0;
char dummy[maxn];
ii w,b;
bool flg;
while(1){
flg = false;
fo(i,0,8){
gets(g[i]);
fo(j,0,8){
if(g[i][j] == 'k') { b = ii(i,j); flg = true; }
if(g[i][j] == 'K') { w = ii(i,j); flg = true; }
}
}
if(!flg) break;
gets(dummy); // extra line
printf("Game #%d: ", ++kase);
if(white_king_checked(w.first, w.second)) printf("white king is in check.\n");
else if(black_king_checked(b.first, b.second)) printf("black king is in check.\n");
else printf("no king is in check.\n");
}
return 0;
}
Human knowledge belongs to the world.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10196 - Check The Check
Try input:
Code: Select all
R.......
k.......
........
........
K.......
........
........
........
........
........
........
........
........
........
........
........
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 6
- Joined: Mon Feb 17, 2014 12:21 am
Re: 10196 - Check The Check
hello, i am having a really hard time with this problem, i am so sure i did not make any mistakes that its impossible to me to find where i am mistaking, i have tried over a 100 test cases, and all seem to be right, keep getting W.A, i am sick of it, please help.
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char matrix[9][9];
char king[2]={'k','K'};
int movx[]={-2,-2,-1,-1,1,1,2,2};
int movy[]={-1,1,-2,2,-2,2,-1,1};
int diagx[]={1,-1,1,-1};
int diagy[]={-1,1,1,-1};
int horx[]={1,0,-1,0};
int hory[]={0,1,0,-1};
bool work(int i, int j, int v){
if (matrix[i][j]=='q' || matrix[i][j]=='Q'){
for (int k=0;k<4;++k){
int aux=horx[k]+i;
int auy=hory[k]+j;
bool no=false;
while (aux>=0 && aux<8 && auy>=0 && auy<8 && !no){
if (matrix[aux][auy]==king[v])
return true;
if (matrix[aux][auy]!='.')
no=true;
aux+=horx[k];
auy+=hory[k];
}
}
for (int k=0;k<4;++k){
int aux=diagx[k]+i;
int auy=diagy[k]+j;
bool no=false;
while (aux>=0 && aux<8 && auy>=0 && auy<8 && !no){
if (matrix[aux][auy]==king[v])
return true;
if (matrix[aux][auy]!='.')
no=true;
aux+=diagx[k];
auy+=diagy[k];
}
}
}else if (matrix[i][j]=='b' || matrix[i][j]=='B'){
for (int k=0;k<4;++k){
int aux=diagx[k]+i;
int auy=diagy[k]+j;
bool no=false;
while (aux>=0 && aux<8 && auy>=0 && auy<8 && !no){
if (matrix[aux][auy]==king[v])
return true;
if (matrix[aux][auy]!='.')
no=true;
aux+=diagx[k];
auy+=diagy[k];
}
}
}else if (matrix[i][j]=='r' || matrix[i][j]=='R'){
for (int k=0;k<4;++k){
int aux=horx[k]+i;
int auy=hory[k]+j;
bool no=false;
while (aux>=0 && aux<8 && auy>=0 && auy<8 && !no){
if (matrix[aux][auy]==king[v])
return true;
if (matrix[aux][auy]!='.')
no=true;
aux+=horx[k];
auy+=hory[k];
}
}
}else if (matrix[i][j]=='n' || matrix[i][j]=='N'){
for (int d=0;d<8;++d){
int aux=i+movx[d];
int auy=j+movy[d];
if (aux>=0 && auy>=0 && aux<8 && auy<8){
if (matrix[aux][auy]==king[v])
return true;
}
}
}else if (matrix[i][j]=='p'){
if (i+1<8 && j+1<8)
if (matrix[i+1][j+1]==king[v])
return true;
if(i+1<8 && j-1>=0)
if (matrix[i+1][j-1]==king[v])
return true;
}else if (matrix[i][j]=='P'){
if (i-1>=0 && j+1<8)
if (matrix[i-1][j+1]==king[v])
return true;
if(i-1>=0 && j-1>=0)
if (matrix[i-1][j-1]==king[v])
return true;
}
return false;
}
int main() {
bool white,black;
int a=1;
while (true){
white=black=false;
int f=0;
for (int i=0;i<8;++i){
scanf("%s",matrix[i]);
for (int j=0;j<8;++j)
if (matrix[i][j]!='.')
f=1;
}
if (f==0) return 0;
int cont=0;
for (int i=0;i<8;++i)
for (int j=0;j<8;++j){
if (matrix[i][j]=='q' || matrix[i][j]=='n' || matrix[i][j]=='b' || matrix[i][j]=='r' || matrix[i][j]=='p'){
black=work(i,j,1);
if (black){
cont++;
printf("Game #%d: white king is in check.\n",a++);
break;
}
}else if (matrix[i][j]=='Q' || matrix[i][j]=='N' || matrix[i][j]=='B' || matrix[i][j]=='R' || matrix[i][j]=='P'){
white=work(i,j,0);
if (white){
cont++;
printf("Game #%d: black king is in check.\n",a++);
break;
}
}
}
if (cont==0)
printf("Game #%d: no king is in check.\n",a++);
}
return 0;
}
Re: 10196 - Check The Check
[ANSI C]
Can someone plz tell me why I got WA ?
PS: 'linhas' = x
'colunas' = y
Some variables are in Portuguse, sorry :/
Thank you !
Can someone plz tell me why I got WA ?
Code: Select all
#include <stdio.h>
#include <stdlib.h>
char field[8][8];
int black_king[2];
int white_king[2];
int isTheEnd()
{
white_king[0] = -1;
white_king[1] = -1;
black_king[0] = -1;
black_king[1] = -1;
int i, j, temp = 1;
for(i = 0; i < 8; ++i)
{
for(j = 0; j < 8; ++j)
{
if(field[i][j] != '.') temp = 0;
if(field[i][j] == 'k')
{
black_king[0] = i;
black_king[1] = j;
}
if(field[i][j] == 'K')
{
white_king[0] = i;
white_king[1] = j;
}
}
}
return temp;
}
int peao_negro(int linha, int coluna)
{
if(linha + 1 <= 7)
{
if(coluna + 1 <= 7) if(field[linha + 1][coluna + 1] == 'K') return 1;
if(coluna - 1 >= 0) if(field[linha + 1][coluna - 1] == 'K') return 1;
}
return 0;
}
int peao_branco(int linha, int coluna)
{
if(linha - 1 >= 0)
{
if(coluna + 1 <= 7) if(field[linha - 1][coluna + 1] == 'k') return 2;
if(coluna - 1 >= 0) if(field[linha - 1][coluna - 1] == 'k') return 2;
}
return 0;
}
int torre_negro(int linha, int coluna)
{
if(linha == white_king[0])
{
int j;
if(coluna < white_king[1])
{
for(j = coluna + 1; j < white_king[1]; j++)
if(field[linha][j] != '.') return 0;
}
else
{
for(j = white_king[1] + 1; j < coluna; j++)
if(field[linha][j] != '.') return 0;
}
return 1;
}
if(coluna == white_king[1])
{
int i;
if(linha < white_king[0])
{
for(i = linha + 1; i < white_king[0]; i++)
if(field[i][coluna] != '.') return 0;
}
else
{
for(i = white_king[0] + 1; i < linha; i++)
if(field[i][coluna] != '.') return 0;
}
return 1;
}
return 0;
}
int torre_branco(int linha, int coluna)
{
if(linha == black_king[0])
{
int j;
if(coluna < black_king[1])
{
for(j = coluna + 1; j < black_king[1]; j++)
if(field[linha][j] != '.') return 0;
}
else
{
for(j = black_king[1] + 1; j < coluna; j++)
if(field[linha][j] != '.') return 0;
}
return 2;
}
if(coluna == black_king[1])
{
int i;
if(linha < black_king[0])
{
for(i = linha + 1; i < black_king[0]; i++)
if(field[i][coluna] != '.') return 0;
}
else
{
for(i = black_king[0] + 1; i < linha; i++)
if(field[i][coluna] != '.') return 0;
}
return 2;
}
return 0;
}
int cavalo_negro(int linhas, int colunas)
{
if(linhas + 2 <= 7)
{
if(colunas + 1 <= 7) if(field[linhas + 2][colunas + 1] == 'K') return 1;
if(colunas - 1 >= 0) if(field[linhas + 2][colunas - 1] == 'K') return 1;
}
if(linhas + 1 <= 7)
{
if(colunas + 2 <= 7) if(field[linhas + 1][colunas + 2] == 'K') return 1;
if(colunas - 2 >= 0) if(field[linhas + 1][colunas - 2] == 'K') return 1;
}
if(linhas - 2 >= 0)
{
if(colunas + 1 <= 7) if(field[linhas - 2][colunas + 1] == 'K') return 1;
if(colunas - 1 >= 0) if(field[linhas - 2][colunas - 1] == 'K') return 1;
}
if(linhas - 1 >= 0)
{
if(colunas + 2 <= 7) if(field[linhas - 1][colunas + 2] == 'K') return 1;
if(colunas - 2 >= 0) if(field[linhas - 1][colunas - 2] == 'K') return 1;
}
return 0;
}
int cavalo_branco(int linhas, int colunas)
{
if(linhas + 2 <= 7)
{
if(colunas + 1 <= 7) if(field[linhas + 2][colunas + 1] == 'k') return 2;
if(colunas - 1 >= 0) if(field[linhas + 2][colunas - 1] == 'k') return 2;
}
if(linhas + 1 <= 7)
{
if(colunas + 2 <= 7) if(field[linhas + 1][colunas + 2] == 'k') return 2;
if(colunas - 2 >= 0) if(field[linhas + 1][colunas - 2] == 'k') return 2;
}
if(linhas - 2 >= 0)
{
if(colunas + 1 <= 7) if(field[linhas - 2][colunas + 1] == 'k') return 2;
if(colunas - 1 >= 0) if(field[linhas - 2][colunas - 1] == 'k') return 2;
}
if(linhas - 1 >= 0)
{
if(colunas + 2 <= 7) if(field[linhas - 1][colunas + 2] == 'k') return 2;
if(colunas - 2 >= 0) if(field[linhas - 1][colunas - 2] == 'k') return 2;
}
return 0;
}
int bispo_negro(int linhas, int colunas)
{
int i, j;
for(i = linhas + 1, j = colunas + 1; i < 8, j < 8; i++, j++)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'K') return 1;
else break;
}
}
for(i = linhas + 1, j = colunas - 1; i < 8, j > -1; i++, j--)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'K') return 1;
else break;
}
}
for(i = linhas - 1, j = colunas - 1; i > -1, j > -1; i--, j--)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'K') return 1;
else break;
}
}
for(i = linhas - 1, j = colunas + 1; i > -1, j < 8; i--, j++)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'K') return 1;
else break;
}
}
return 0;
}
int bispo_branco(int linhas, int colunas)
{
int i, j;
for(i = linhas + 1, j = colunas + 1; i < 8, j < 8; i++, j++)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'k') return 2;
else break;
}
}
for(i = linhas + 1, j = colunas - 1; i < 8, j > -1; i++, j--)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'k') return 2;
else break;
}
}
for(i = linhas - 1, j = colunas - 1; i > -1, j > -1; i--, j--)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'k') return 2;
else break;
}
}
for(i = linhas - 1, j = colunas + 1; i > -1, j < 8; i--, j++)
{
if(field[i][j] != '.')
{
if(field[i][j] == 'k') return 2;
else break;
}
}
return 0;
}
int main()
{
int i, j, game = 0;
int cheque[200] = {0};
while(1)
{
scanf("%s %s %s %s %s %s %s %s", field[0], field[1], field[2], field[3], field[4], field[5], field[6], field[7]);
if(isTheEnd()) break;
for(i = 0; i < 8; i++)
{
if(cheque[game] != 0) break;
for(j = 0; j < 8; j++)
{
if(cheque[game] != 0) break;
switch(field[i][j])
{
case 'p':
cheque[game] = peao_negro(i, j);
break;
case 'P':
cheque[game] = peao_branco(i, j);
break;
case 'r':
cheque[game] = torre_negro(i, j);
break;
case 'R':
cheque[game] = torre_branco(i, j);
break;
case 'n':
cheque[game] = cavalo_negro(i, j);
break;
case 'N':
cheque[game] = cavalo_branco(i, j);
break;
case 'b':
cheque[game] = bispo_negro(i, j);
break;
case 'B':
cheque[game] = bispo_branco(i, j);
break;
case 'q':
if(bispo_negro(i, j) == 1 || torre_negro(i, j) == 1) cheque[game] = 1;
break;
case 'Q':
if(bispo_branco(i, j) == 2 || torre_branco(i, j) == 2) cheque[game] = 2;
break;
}
}
}
game++;
}
for(i = 0; i < game; i++)
{
if(i != 0) printf("\n");
if(cheque[i] == 0) printf("Game #%i: no king is in check.", i + 1);
if(cheque[i] == 1) printf("Game #%i: white king is in check.", i + 1);
if(cheque[i] == 2) printf("Game #%i: black king is in check.", i + 1);
}
}
'colunas' = y
Some variables are in Portuguse, sorry :/
Thank you !