Target Practice (Codeforces 1873C)
Tags: Math, implementation

A $$$10 \times 10$$$ target is made out of five "rings" as shown. Each ring has a different point value: the outermost ring — 1 point, the next ring — 2 points, ..., the center ring — 5 points.  Vlad fired several arrows at the target. Help him determine how many points he got.

Input: The input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.Each test case consists of 10 lines, each containing 10 characters. Each character in the grid is either $$$\texttt{X}$$$ (representing an arrow) or $$$\texttt{.}$$$ (representing no arrow).

Output: For each test case, output a single integer — the total number of points of the arrows.

Note: In the first test case, there are three arrows on the outer ring worth 1 point each, two arrows on the ring worth 3 points each, and two arrows on the ring worth 4 points each. The total score is $$$3 \times 1 + 2 \times 3 + 2 \times 4 = 17$$$. In the second test case, there aren't any arrows, so the score is $$$0$$$.

Sample Inputs:
4
X.........
..........
.......X..
.....X....
......X...
..........
.........X
..X.......
..........
.........X
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
....X.....
..........
..........
..........
..........
..........
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX

Sample Outputs:
17
0
5
220

Solution (Python):
n = int(input())
score = [[0] * 10 for _ in range(10)]
for i in range(10):
    for j in range(10):
        score[i][j] = min(i, j, 9 - i, 9 - j) + 1

def func(i, nums):
    res = 0
    for j in range(10):
        if nums[j] == 'X':
            res += score[i][j]
    return res
for _ in range(n):
    res = 0
    for i in range(10):
        nums = input()
        res += func(i, nums)
    print(res)

Solution (Python):
def readl1():
    points = 0
    line1 = input()
    for square in line1:
        if square == 'X':
            points += 1
    return points

def readl2():
    points = 0
    line2 = input()
    for (i, square) in enumerate(line2):
        if square == 'X':
            if i in [0, 9]:
                points += 1
            else:
                points += 2
    return points

def readl3():
    points = 0
    line3 = input()
    for (i, square) in enumerate(line3):
        if square == 'X':
            if i in [0, 9]:
                points += 1
            elif i in [1, 8]:
                points += 2
            else:
                points += 3
    return points

def readl4():
    points = 0
    line4 = input()
    for (i, square) in enumerate(line4):
        if square == 'X':
            if i in [0, 9]:
                points += 1
            elif i in [1, 8]:
                points += 2
            elif i in [2, 7]:
                points += 3
            else:
                points += 4
    return points

def readl5():
    points = 0
    line5 = input()
    for (i, square) in enumerate(line5):
        if square == 'X':
            if i in [0, 9]:
                points += 1
            elif i in [1, 8]:
                points += 2
            elif i in [2, 7]:
                points += 3
            elif i in [3, 6]:
                points += 4
            else:
                points += 5
    return points
tests = int(input())
for test in range(tests):
    points = 0
    points += readl1()
    points += readl2()
    points += readl3()
    points += readl4()
    points += readl5()
    points += readl5()
    points += readl4()
    points += readl3()
    points += readl2()
    points += readl1()
    print(points)

Solution (Python):
import math
import sys
line1 = '1111111111'
line2 = '1222222221'
line3 = '1233333321'
line4 = '1234444321'
line5 = '1234554321'
tests = int(sys.stdin.readline().strip())
for i in range(tests):
    summ = 0
    test1 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test1[ii] == 'X':
            summ += 1
    test2 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test2[ii] == 'X':
            summ += int(line2[ii])
    test3 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test3[ii] == 'X':
            summ += int(line3[ii])
    test4 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test4[ii] == 'X':
            summ += int(line4[ii])
    test5 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test5[ii] == 'X':
            summ += int(line5[ii])
    test6 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test6[ii] == 'X':
            summ += int(line5[ii])
    test7 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test7[ii] == 'X':
            summ += int(line4[ii])
    test8 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test8[ii] == 'X':
            summ += int(line3[ii])
    test9 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test9[ii] == 'X':
            summ += int(line2[ii])
    test10 = sys.stdin.readline().strip().strip()
    for ii in range(len(test1)):
        if test10[ii] == 'X':
            summ += 1
    print(summ)