Where's the Bishop? (Codeforces 1692C)
Tags: Implement, implementation

Mihai has an $$$8 \times 8$$$ chessboard whose rows are numbered from $$$1$$$ to $$$8$$$ from top to bottom and whose columns are numbered from $$$1$$$ to $$$8$$$ from left to right.Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edges of the board. (In other words, the row and column of the bishop are between $$$2$$$ and $$$7$$$, inclusive.)The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked.   An example of a bishop on a chessboard. The squares it attacks are marked in red. Mihai has marked all squares the bishop attacks, but forgot where the bishop was! Help Mihai find the position of the bishop.

Input: The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 36$$$) — the number of test cases. The description of test cases follows. There is an empty line before each test case.Each test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each of these characters is either '#' or '.', denoting a square under attack and a square not under attack, respectively.

Output: For each test case, output two integers $$$r$$$ and $$$c$$$ ($$$2 \leq r, c \leq 7$$$) — the row and column of the bishop. The input is generated in such a way that there is always exactly one possible location of the bishop that is not on the edge of the board.

Note: The first test case is pictured in the statement. Since the bishop lies in the intersection row $$$4$$$ and column $$$3$$$, the correct output is 4 3.

Sample Inputs:
3
.....#..
#...#...
.#.#....
..#.....
.#.#....
#...#...
.....#..
......#.
#.#.....
.#......
#.#.....
...#....
....#...
.....#..
......#.
.......#
.#.....#
..#...#.
...#.#..
....#...
...#.#..
..#...#.
.#.....#
#.......

Sample Outputs:
4 3
2 2
4 5

Solution (Python):
import math

def decoder(n, arr):
    fLoc = None
    lLoc = None
    for i in range(n):
        count = 0
        fLoc = None
        lLoc = None
        for j in range(n):
            if arr[i][j] == '#':
                if fLoc is None:
                    fLoc = [i, j]
                else:
                    lLoc = [i, j]
                count += 1
        if count == 2:
            break
    role = lLoc[-1] - fLoc[-1]
    role = math.ceil(role / 2) + 1
    return [fLoc[0] + role, fLoc[-1] + role]
if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        input()
        arr = []
        for _ in range(8):
            x = input()
            arr.append(x)
        result = decoder(8, arr)
        print(*result)

Solution (Python):
T = int(input())
for m in range(T):
    l1 = []
    input()
    for i in range(8):
        str1 = input()
        l1.append(str1)
    for i in range(1, 7):
        for j in range(1, 7):
            if l1[i][j] == '#' and l1[i + 1][j + 1] == '#' and (l1[i + 1][j - 1] == '#') and (l1[i - 1][j - 1] == '#') and (l1[i - 1][j + 1] == '#'):
                ans = [i + 1, j + 1]
                break
    print(*ans)

Solution (Python):
exec(int(input()) * "k=-1\nfor i in range(9):\n if~(j:=input().find('#.#'))&k<0:k=j;print(i+1,j+2)\n")