蓝桥杯刷题

题目:门牌制作 - 蓝桥云课 (lanqiao.cn)

sum=0
for i in range(1,2021):
    s=str(i)
    sum+=s.count('2');
print(sum)

题目:卡片 - 蓝桥云课 (lanqiao.cn)

import os
import sys

# 请在此输入您的代码
num=0
for i in range(1,100000):
  num+=str(i).count('1')
  if(num>2021):
    break
print(i-1)

自己稍微验证一下,发现1用的是最快的

题目:分数 - 蓝桥云课 (lanqiao.cn)

from fractions import Fraction
sum = 1
for i in range(1,20):
    a=Fraction(1,2**i)
    sum+=a
print(sum)

Fraction函数可以自动进行分数运算并约分

from fractions import Fraction
a=Fraction(6,81)
print(a)
>>>2/27

题目:星期一 - 蓝桥云课 (lanqiao.cn)

weekday()函数不同数字的意义

表示 意义
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
4 Friday
5 Saturday
6 Sunday
from datetime import *
start=date(1901,1,1)
end=date(2000,12,31)
result=end-start
#result=36524
#print(start.weekday())
a=36524
print(a//7)

题目:顺子日期 - 蓝桥云课 (lanqiao.cn)

from datetime import *
begin=date(2022,1,1)
end=date(2022,12,31)
s=["012","123","234","345","456","567","678","789"]
day=timedelta(days=1)#让day也变为一个date对象,方便相加
result=0
while begin<=end:
	str1=str(begin).replace('-','')
	for i in range(6):
		if str1[i:i+3] in s:
			result+=1
			break;
	begin+=day
print(result)

# #test1:
# str2='20221231'
# for i in range(6):
# 	print(str2[i:i+3])

题目:修剪灌木 - 蓝桥云课 (lanqiao.cn)

n=int(input())
for i in range(1,n+1):
    print(max((i-1)*2,(n-i)*2))

题目:最少砝码 - 蓝桥云课 (lanqiao.cn)

n=int(input())
i=1
result=1
while i<n:
    i=i*3+1
    result+=1
print(result)

题目:日期格式 - 蓝桥云课 (lanqiao.cn)

y,r=input().split()#在同一行进行输入
y=int(y)
a=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
print(a[y-1],end='')
print(r.zfill(2))#zfill是字符串填补函数

题目:成绩分析 - 蓝桥云课 (lanqiao.cn)

1:

n=int(input())
min_grade=100
max_grade=0
sum=0
for i in range (n):
    grade=int(input())
    sum+=grade
    if grade>max_grade:
        max_grade=grade
    if grade<min_grade:
        min_grade=grade

print(max_grade)
print(min_grade)
print('{:.2f}'.format(sum/n))

2:

n=int(input())
a=[]
for i in range (n):
    a.append(int(input()))
print(max(a))
print(min(a))
print('{:.2f}'.format(sum(a)/n))

题目:合法日期 - 蓝桥云课 (lanqiao.cn)

巧妙使用异常来处理

from datetime import *
m=int(input())
d=int(input())
try:
    a=date(2021,m,d)
    #print(a)
    print('yes')
except:
    print('no')

题目:时间加法 - 蓝桥云课 (lanqiao.cn)

a=int(input())
b=int(input())
t=int(input())
sum=b+t
print(a+sum//60)
print(sum%60)

题目:扫雷 - 蓝桥云课 (lanqiao.cn)

n,m=map(int,input().split()) #map函数的作用相当于把输入的类型强制转化为int型
a=[list(map(int,input().split())) for _ in range(n)] #把二维数组进行输入
b=[[0]*m for _ in range(n)] #创建一个新的二维数组
for i in range(n):
    for j in range(m):
        if a[i][j]==1:
            b[i][j]=9
        else:
            for k in range(i-1,i+2):
                for l in range(j-1,j+2):
                    if 0<=k<n and 0<=l<m:
                        if a[k][l]==1:
                            b[i][j]+=1
for r in range(n):
    for c in range(m):
        print(b[r][c],end=" ")
    print()

题目:大写 - 蓝桥云课 (lanqiao.cn)

a=input()
print(a.upper())

题目:标题统计 - 蓝桥云课 (lanqiao.cn)

a=input()
b=0
for i in a:
    if isinstance(i,str)://isinstance()判断i是否是后面这种类型
        b+=1
    if isinstance(i,int):
        b+=1
    if i==" ":
        b-=1
print(b)

题目:求和 - 蓝桥云课 (lanqiao.cn)

sum=0
for i in range(1,2020):
    if '1' in str(i) or '0' in str(i) or '2' in str(i) or '9' in str(i):
        sum+=i
print(sum)

题目:天数 - 蓝桥云课 (lanqiao.cn)

from datetime import *
a=int(input())
if a==2:
    print(28)
else:
    try:
        b=date(2021,a,31)
        print(31)
    except:
        print(30)
a=int(input())
m=['31','28','31','30','31','30','31','31','30','31','30','31']
print(m[a-1])
posted @ 2023-11-28 19:26  Jinx8823  阅读(36)  评论(0编辑  收藏  举报