Understanding this

Hello, can someone explain this little problem to me ? a bit of illustration would be great ^^


Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.

Input
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.

Output
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.

Examples
input
3
xxo
xox
oxx
output
YES
input
4
xxxo
xoxo
oxox
xxxx
output
NO


I don't specifically understand this part:
Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
which I think is the key to solve it/understand it.
Pick one square on the board.

Unless it's on the edge, it has a square on its left, a square on its right, a square above and a square below.

Those are the four adjacent squares.

Each of those adjacent squares can have an x in, or an o

Could be four 'x'. Or four 'o'. Or one 'x' and three 'o'. Or two of each. or three 'x' and one 'o'.

If it's four 'o', or two 'o', or zero 'o', then this square that you picked does have an even number of adjacent cells with 'o' in it.

Now look at EVERY square on the board. Does EVERY square have an even number of adjacent cells with 'o' in it?

@Moschops:

Can you illustrate it a little bit more on such an input ? :c

input
3
xxo
xox
oxx


Also, does that limit the cell to have it right beside it, or it could be at the end of the row/column? Like
xxo
this row , for the first cell 'x' the o is considered adjacent to it ?

Thanks ^^
Last edited on
Adjacent means ONLY right next to. NOT anything in the same row. NOT anything in the same column.

input
3
xxo
xox
oxx


The 'x' in the top left has TWO adjacent values; two 'x' and zero 'o'.
The 'o' in the middle has FOUR adjacent values; four 'x' and zero 'o'.

This problem is actually very clear; I suspect you're simply not used to having to understand precise details from reading. Understanding the problem is a very, very fundamental part of programming and becoming good at it would be very helpful to you if you're going to stick with programming.
Last edited on
Topic archived. No new replies allowed.