A. Vlad and the Best of Five
Vladislav has a string of length 5 5 5, whose characters are each either A \texttt{A} A or B \texttt{B} B.
Which letter appears most frequently: A \texttt{A} A or B \texttt{B} B?
Input
The first line of the input contains an integer t t t ( 1 ≤ t ≤ 32 1 \leq t \leq 32 1≤t≤32) — the number of test cases.
The only line of each test case contains a string of length 5 5 5 consisting of letters A \texttt{A} A and B \texttt{B} B.
All t t t strings in a test are different (distinct).
Output
For each test case, output one letter ( A \texttt{A} A or B \texttt{B} B) denoting the character that appears most frequently in the string.
Example
input
8
ABABB
ABABA
BBBAB
AAAAA
BBBBB
BABAA
AAAAB
BAAAA
output
B
A
B
A
B
A
A
A
Tutorial
哪个多输出哪个
Solution
for _ in range(int(input())):
mp = Counter(input().strip())
print("A" if mp['A'] > mp['B'] else "B")
B. Vlad and Shapes
Vladislav has a binary square grid of n × n n \times n n×n cells. A triangle or a square is drawn on the grid with symbols 1 \texttt{1} 1. As he is too busy being cool, he asks you to tell him which shape is drawn on the grid.
- A triangle is a shape consisting of k k k ( k > 1 k>1 k>1) consecutive rows, where the i i i-th row has 2 ⋅ i − 1 2 \cdot i-1 2⋅i−1 consecutive characters 1 \texttt{1} 1, and the central 1s are located in one column. An upside down triangle is also considered a valid triangle (but not rotated by 90 degrees).
Two left pictures contain examples of triangles: k = 4 k=4 k=4, k = 3 k=3 k=3. The two right pictures don’t contain triangles.
- A square is a shape consisting of k k k ( k > 1 k>1 k>1) consecutive rows, where the i i i-th row has k k k consecutive characters 1 \texttt{1} 1, which are positioned at an equal distance from the left edge of the grid.
Examples of two squares: k = 2 k=2 k=2, k = 4 k=4 k=4.
For the given grid, determine the type of shape that is drawn on it.
Input
The first line contains a single integer t t t ( 1 ≤ t ≤ 100 1 \leq t \leq 100 1≤t≤100) — the number of test cases.
The first line of each test case contains a single integer n n n ( 2 ≤ n ≤ 10 2 \leq n \leq 10 2≤n≤10) — the size of the grid.
The next n n n lines each contain n n n characters 0 \texttt{0} 0 or 1 \texttt{1} 1.
The grid contains exactly one triangle or exactly one square that contains all the 1 \texttt{1} 1s in the grid. It is guaranteed that the size of the triangle or square is greater than 1 1 1 (i.e., the shape cannot consist of exactly one 1).
Output
For each test case, output “SQUARE” if all the 1 \texttt{1} 1s in the grid form a square, and “TRIANGLE” otherwise (without quotes).
Example
input
6
3
000
011
011
4
0000
0000
0100
1110
2
11
11
5
00111
00010
00000
00000
00000
10
0000000000
0000000000
0000000000
0000000000
0000000000
1111111110
0111111100
0011111000
0001110000
0000100000
3
111
111
111
output
SQUARE
TRIANGLE
SQUARE
TRIANGLE
TRIANGLE
SQUARE
Tutorial
暴力模拟判断即可
Solution
def solve():
n = int(input())
g = [input().strip() for __ in range(n)]
for i in range(n):
for j in range(n):
if g[i][j] == '1':
x = y = 0
while i + x < n and g[i + x][j] == '1':
x += 1
while j + y < n and g[i][j + y] == '1':
y += 1
if x ^ y:
print("TRIANGLE")
return
for a in range(x):
for b in range(y):
if g[i + a][j + b] == '0':
print("TRIANGLE")
return
print("SQUARE")
return
for _ in range(int(input())):
solve()
C. Vlad and a Sum of Sum of Digits
Please note that the time limit for this problem is only 0.5 seconds per test.
Vladislav wrote the integers from 1 1 1 to n n n, inclusive, on the board. Then he replaced each integer with the sum of its digits.
What is the sum of the numbers on the board now?
For example, if n = 12 n=12 n=12 then initially the numbers on the board are:
1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. 1,2,3,4,5,6,7,8,9,10,11,12.
Then after the replacement, the numbers become:
1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 , 2 , 3. 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3. 1,2,3,4,5,6,7,8,9,1,2,3.
The sum of these numbers is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 2 + 3 = 51 1+2+3+4+5+6+7+8+9+1+2+3=51 1+2+3+4+5+