Problem Statement
You have an 8x8 chessboard. Each cell is either empty or contains a single rook. You are given a description of the chessboard in the String[] board. Empty cells are represented by '.' (period), rooks are represented by 'R'. The character board[r][c] describes the cell in row r, column c. (Hence, both rows and columns are numbered from 0 to 7.)
There are many rooks. More precisely, it is guaranteed that the board has strictly more rooks than empty squares.
Your task is to choose exactly five rooks. The five chosen rooks will remain on the chessboard, all other rooks will be removed. The five rooks must be chosen in such a way that on the resulting chessboard no two of them will attack each other. In other words, the five chosen rooks must be in five distinct rows and at the same time they must be in five distinct columns. It is guaranteed that for the given constraints such a set of five rooks always exists.
Return a int[] with exactly 10 elements. The first two elements denote the row and column of the first rook, the third and fourth element describe the second rook, and so on. If there are multiple solutions, you may return any one of them.
Definition
- Class:
- FiveRooks
- Method:
- find
- Parameters:
- String[]
- Returns:
- int[]
- Method signature:
- int[] find(String[] board)
- (be sure your method is public)
Constraints
- board will have exactly 8 elements.
- Each element of board will have exactly 8 characters.
- Each character of board will be '.' or 'R'.
- There are strictly more 'R' characters than '.' characters within all elements of board.
Examples
{ "RRRRRRRR", "RRRRRRRR", "RRRRRRRR", "RRRRRRRR", "R.......", "........", "........", "........" }Returns: {0, 7, 1, 3, 2, 4, 3, 6, 4, 0 }The return value corresponds to the following chosen rooks: { "RRRRRRR*", "RRR*RRRR", "RRRR*RRR", "RRRRRR*R", "*.......", "........", "........", "........" }{ "R.R.R.R.", ".R.R.R.R", "R.R.R.R.", ".R.RRR.R", "R.R.R.R.", ".R.R.R.R", "R.R.R.R.", ".R.R.R.R" }Returns: {0, 0, 1, 7, 2, 6, 3, 5, 4, 4 }{ "RRRRRRRR", "RRRRRRRR", "RRRRRRRR", "RRRRRRRR", "RRRRRRRR", "RRRRRRRR", "RRRRRRRR", "RRRRRRRR" }Returns: {0, 7, 1, 3, 2, 4, 3, 6, 4, 0 }{ ".RRRRRR.", "RRRRRRRR", "....RRRR", "...RRRR.", "..RRRR..", ".RRRR...", "RRRR....", "RRR....." }Returns: {1, 7, 2, 6, 3, 5, 4, 4, 5, 3 }{ ".RRRRRR.", "RRRRRRRR", "....RRRR", "...RRRR.", "..RRRR..", ".RRRR...", "RRRRRRRR", ".RRRRRR." }Returns: {1, 7, 2, 6, 3, 5, 4, 4, 5, 3 }{ ".RRRRRR.", "RRRRRRRR", ".RRRR...", "..RRRR..", "...RRRR.", "....RRRR", "RRRRRRRR", ".RRRRRR." }Returns: {1, 7, 3, 5, 4, 4, 6, 2, 7, 1 }