Stripes (Codeforces 1742C)
Tags: Implement, implementation

On an $$$8 \times 8$$$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the cells through which it passes.Determine which color was used last.  The red stripe was painted after the blue one, so the answer is R. 

Input: The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 4000$$$) — 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 'R', 'B', or '.', denoting a red square, a blue square, and an unpainted square, respectively.It is guaranteed that the given field is obtained from a colorless one by drawing horizontal red rows and vertical blue columns.At least one stripe is painted.

Output: For each test case, output 'R' if a red stripe was painted last, and 'B' if a blue stripe was painted last (without quotes).

Note: The first test case is pictured in the statement.In the second test case, the first blue column is painted first, then the first and last red rows, and finally the last blue column. Since a blue stripe is painted last, the answer is B.

Sample Inputs:
4
....B...
....B...
....B...
RRRRRRRR
....B...
....B...
....B...
....B...
RRRRRRRB
B......B
B......B
B......B
B......B
B......B
B......B
RRRRRRRB
RRRRRRBB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB
........
........
........
RRRRRRRR
........
........
........
........

Sample Outputs:
R
B
B
R

Solution (Python):
from sys import stdin
INF = float('inf')
input = stdin.readline

def read_str():
    return input().strip()

def read_int():
    return int(input().strip())

def read_lst():
    return list(map(int, input().strip().split()))

def read_map():
    return map(int, input().strip().split())

def ok(b):
    print('YES' if b else 'NO')

def solve():
    ans = False
    for i in range(9):
        if read_str().count('R') == 8:
            ans = True
    print('R' if ans else 'B')

def main():
    for _ in range(read_int()):
        solve()
if __name__ == '__main__':
    main()

Solution (Python):
import sys
tests = int(sys.stdin.readline().strip())
for i in range(tests):
    f = sys.stdin.readline()
    r = 0
    for ii in range(8):
        line = sys.stdin.readline().strip()
        if line == 'RRRRRRRR':
            r += 1
    if r > 0:
        print('R')
    else:
        print('B')

Solution (Python):
import sys
for _ in range(int(input())):
    bl = False
    b = 'B'
    p = 0
    for t in sys.stdin:
        cont = 0
        if len(t) < 2 and bl:
            break
        elif bl or len(t) < 2:
            continue
        p += 1
        for j in t:
            if j != 'R':
                break
            cont += 1
        if cont == 8:
            b = 'R'
            bl = True
        elif p == 8:
            bl = True
    print(b)