1
AC when the number of correct answers and the number of questions match
N , M = map(int,input().split())
if N == M:
print("Yes")
else:
print("No")
2 Coming first in lexicographical order is synonymous with small numbers. Therefore, the small value should be repeated a large number of times.
a, b = map(int,input().split())
ans = str(min(a, b)) * max(a, b)
print(ans)
3
The problem that chokudai also wanted to solve. The problem statement is complex, but the problem statement can be reduced to the problem that an i is the smallest of all js. Therefore, if you hold the value from the left and always judge whether it is the minimum, you can solve it with $ O (N) $.
N = int(input())
P = list(map(int, input().split()))
now = P[0]
ans = 1
for i in range(1, N):
if now >= P[i]:
now = P[i]
ans += 1
print(ans)
4
The question of how many pairs of integers are suitable for the condition.
From the constraint, we can see that it can be solved by $ O (N) $. Also, it seems that there is no clear rule when writing out about 1 to 20.
The point of this problem is to use only 1 to 9 values, so create a 9 * 9 two-dimensional array. Count it with for, and the combination of two numbers is the answer.
from pprint import pprint
N = int(input())
digit_cnt = list([0] * 9 for _ in range(9))
now = 1
for i in range(1, N + 1):
str_i = str(i)
row = int(str_i[0])
column = int(str_i[-1])
if row != 0 and column != 0:
digit_cnt[row - 1][column - 1] += 1
# pprint(digit_cnt)
ans = 0
for i in range(9):
for j in range(9):
ans += digit_cnt[i][j] * digit_cnt[j][i]
print(ans)
Recommended Posts