A:门牌制作
count = 0
for i in range(1,2021):
count += str(i).count("2")
print(count)
B:既约分数
def check(a,b):
if b == 0 or a == 0:
return "Error"
else:
while a%b != 0:
a,b = b,a%b
return b
def check_more(a,b):
return check(a,b) == 1
count = 0
for i in range(1,2021):
for j in range(1,2021):
if check_more(i,j) or check_more(j,i):
count += 1
print(count)
C:蛇形填数
li = [[0 for i in range(100)] for i in range(100)]
num = 1
for i in range(100):
for j in range(i+1):
if i%2 == 0:
li[i][j] = num
else:
li[i][i-j] = num
num += 1
print(li[38][19])
D:跑步锻炼
import datetime
leap_month=[0,31,29,31,30,31,30,31,31,30,31,30,31]
ordi_month=[0,31,28,31,30,31,30,31,31,30,31,30,31]
sum_journey=0
for year in range(2000,2021):
if(year%4==0 and year%100!=0) or year%400==0:
for month_index in range(1,13):
month=leap_month[month_index]
for day in range(1,month+1):
date=datetime.datetime(year,month_index,day)
week=date.weekday()
if day!=1 and week!=0:
sum_journey+=1
else:
sum_journey+=2
if year==2020 and month_index==10 and day==1:
print("{}年{}月{}日:{}KM".format(year,month_index,day,sum_journey))
else:
for month_index in range(1,13):
month=ordi_month[month_index]
for day in range(1,month+1):
date=datetime.datetime(year,month_index,day)
week=date.weekday()
if day!=1 and week!=0:
sum_journey+=1
else:
sum_journey+=2
E:七段码
from itertools import combinations as comb
L = list('abcdefg')
C = [[''.join(c) for c in list(comb(L,i+1)) if 'g' in c] for i in range(7)]
D =[]
for i in C:
for j in i:
D.append(j)
X = [e for e in D if 'a' in e and 'b' not in e and 'f' not in e or 'd' in e and 'c' not in e and 'e' not in e]
E = [d for d in D if d not in X]
L = list('abcdef')*2
A = [L[i:j] for i in range(len(L)) for j in range(i+1,len(L)+1) if len(L[i:j])<7]
B = list(set([''.join(sorted(a)) for a in A]))
F = sorted(B + E)
print(len(F))
F:成绩统计
n = int(input())
li = []
for i in range(n):
m = int(input())
li.append(m)
menu = {"优秀":0,"及格":0,"其他":0}
for x in li:
if 60<= x:
menu["及格"] += 1
if x >= 85:
menu["优秀"] += 1
else:
menu["其他"] += 1
a,b = round(menu["优秀"]*100/n),round(menu["及格"]*100/n)
print(str(a)+"%",str(b)+"%")
G:回文日期
n = int(input())
def is_pal(x):
x = str(x)
return x == x[::-1]
def is_text(x):
x = str(x)
return x[0]==x[2]==x[5]==x[7] and x[1]==x[3]==x[4]==x[6]
def is_check(x):
x = str(x)
if x[4:6] > "12" or x[6:8] > "31":
return False
else:
a = int(x[:4])
leap_month = [0,31,29,31,30,31,30,31,31,30,31,30,31]
ordi_month = [0,31,28,31,30,31,30,31,31,30,31,30,31]
if (a%4 == 0 and a%100 != 0) or a%400 == 0:
if leap_month[int(x[4:6])] >= int(x[6:8]):
return True
else:
return False
else:
if ordi_month[int(x[4:6])] >= int(x[6:8]):
return True
else:
return False
num = n+1
while True:
if is_pal(num) and is_check(num):
print(num)
break
else:
num += 1
while True:
if is_text(num) and is_check(num):
print(num)
break
else:
num += 1
H:子串分值和
def f(s):
a = set()
for i in s:
a.add(i)
return len(a)
s = input()
f_all = 0
for i in range(len(s)):
for j in range(len(s)):
if i <= j:
f_all += f(s[i:j+1])
print(f_all)
I:平面切分
N=int(input())
lis=[]
for i in range(N):
lis.append(tuple(map(int,input().split())))
crosspoint_x_set=set()
lis = list(set([i for i in lis]))
each_line_sum = 2 #一开始只有一条直线的时候,平面被分为二个部分
for i in range(1,len(lis)):
crosspoint_x_set.clear()
for j in range(i):
if lis[i][0] != lis[i-j-1][0]: #代表二条直线不平行
x=round((lis[i][1]-lis[i-j-1][1])/(lis[i-j-1][0]-lis[i][0]),4)
crosspoint_x_set.add(x)
each_line_sum += (len(crosspoint_x_set)+1)
print(each_line_sum)
J:字串排序
不会