蓝桥杯
第十四届蓝桥杯大赛软件赛国赛Python大学C组
跑步计划
1月1日 -> 4月3日相差92天,所以得出1月1日为星期日,遍历整年,只要包含“1”就+5,否则+1,最终计算可得答案为1333,直接输出1333就行
# month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
# weekday = 0
# res = 0
# for i in range(1,13):
# for j in range(1, month[i] + 1):
# if weekday == 1 or '1' in str(j) or '1' in str(i):
# res+=5
# else:
# res+=1
# weekday = (weekday + 1) % 7
# print(res)
print(1333)
混乘数字
遍历一遍1到1000000,对于是否判断出现次数相同,可以考虑排序一样就可以了,最后结果为590,为防止超时直接输出590就可以了
# def find(n):
# for a in range(1, int(n ** 0.5) + 1):
# if n % a == 0:
# b = n // a
# num_str = str(n)
# ab_str = str(a) + str(b)
# if sorted(num_str) == sorted(ab_str):
# return True
# return False
#
# res = 0
# for i in range(1, 1000001):
# if find(i):
# res+=1
# print(res)
print(590)
混乘数字
建议使用 PyPy3 提交本题,不然会超时
n = int(input())
res = 0
while n!=0:
sum =0
for i in str(n):
sum+=int(i)
n = n-sum
res +=1
print(res)
定时任务
这题目看着比较难,其实只要慢慢做是可以做出来的,别害怕
def find(mystr,mymin,mymax):
res = []
if mystr == '*':
for i in range(mymin,mymax+1):
res.append(i)
return res
if ',' in mystr:
temp = mystr.split(',')
for i in temp:
res.append(int(i))
return res
if '-' in mystr:
start, end = map(int, mystr.split('-'))
for i in range(start, end + 1):
res.append(i)
return res
res.append(int(mystr))
return res
second, minute, hour, day, month = input().split()
seconds = find(second,0,59)
minutes = find(minute,0,59)
hours = find(hour,0,23)
days = find(day,1,31)
months = find(month,1,12)
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
valid_days = []
for month in months:
for day in days:
if day <= month_days[month - 1]:
valid_days.append((month, day))
res = len(seconds) * len(minutes) * len(hours) * len(valid_days)
print(res)

浙公网安备 33010602011771号