s = 0
for i in range(1,2021):
s += str(i).count('2')
print(s)
# 624
nums = [[2, 2, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 2, 2, 0, 2],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 2, 2],
[0, 0, 2, 0, 2, 0],
]
n = 0
for i in range(len(nums)):
for j in range(len(nums[0])):
if j+4 <= len(nums[0]):
a = nums[i][j:j+4]
if a == [2,0,2,0]:
n+=1
if i+3<len(nums):
b = nums[i][j]*1000+nums[i+1][j]*100+nums[i+2][j]*10+nums[i+3][j]
if b == 2020:
n+=1
if i+3<len(nums) and j+3 < len(nums[0]):
c = nums[i][j]*1000+nums[i+1][j+1]*100+nums[i+2][j+2]*10+nums[i+3][j+3]
if c == 2020:
n+=1
print(n)
import datetime
a = datetime.date(2000,1,1)
b = datetime.date(2020,10,2)
num = 0
while True:
if a == b:
break
if a.day == 1:
num+=2
a = a+datetime.timedelta(days=1)
continue
if a.isoweekday() == 1:
num+=2
a = a + datetime.timedelta(days=1)
continue
num+=1
a = a + datetime.timedelta(days=1)
print(num)
# 8879
# 代码运行
lst = [[] for i in range(40)]
num = 1
lst[0].append(1)
for i in range(2, 40):
if i % 2 == 0:
for j in range(i):
num += 1
lst[j].append(num)
else:
for j in range(i):
num += 1
lst[i - j - 1].append(num)
for i in range(len(lst)):
print(i + 1, lst[i])
print(lst[19][19])
也可以找规律,斜着的一行数
# 当所有的字符全全部倒序的时候重新排序的次数就越多,所用的字符就越少
# 又因为要求字典序最小,所以字母应该是前n位
# 由于冒泡排序的特征,完全倒序的情况下,交换的次数是(n-1)+(n-2)......2+1
# 算出当有15字符完全倒序的时候为,105,所以,只需要在此基础上稍加修改即可,
# 又因为需要保证字典序最小,即字符串的第一个字目应该尽量的小,所以将j前提5个字符
# 'abcdefghijklmno'
# print('jonmlkihgfedcba')
n = int(input())
y = 0
j = 0
for i in range(n):
num = int(input())
if num >= 85:
y+=1
if num >=60:
j +=1
print('{:.0f}%'.format((j/n)*100))
print('{:.0f}%'.format((y/n)*100))
import collections # 标准库
str1 = input()
dit = collections.defaultdict(int)
for i in str1:
dit[i] += 1
dit = dict(sorted(dit.items()))
dit = sorted(dit.items(),key=lambda x:x[1],reverse=True)
print(dit[0][0])
print(dit[0][1])
# 递归
n = int(input())
lst1 = []
for i in range(n):
lst1.append([int(i) for i in input().split()])
ll = []
# 递归函数效率效率太低,运行超时
def df2(l, i, j, s, c):
if len(l[i]) <= j or j < 0:
return
s += l[i][j]
i += 1
if i == n:
if abs(c) <= 1:
ll.append(s)
return
df2(l, i, j, s, c + 1)
df2(l, i, j + 1, s, c - 1)
df2(lst1,0,0,0,0)
print(max(ll))
# 循环
n = int(input())
trg = [list(map(int, input().split())) for i in range(n)]
f = []
def path(n, trg):
for i in range(n):
f.append([])
for j in range(i + 1):
f[i].append(0)
if i == 0:
f[i][j] = trg[i][j]
elif j == 0:
f[i][j] = f[i - 1][j] + trg[i][j]
elif j == i:
f[i][j] = f[i - 1][j - 1] + trg[i][j]
else:
f[i][j] = max(f[i - 1][j - 1], f[i - 1][j]) + trg[i][j]
if n % 2 != 0:
return f[n - 1][n // 2]
else:
return max(f[n - 1][n // 2], f[n - 1][(n - 1) // 2])
print(path(n, trg))