当前位置:   article > 正文

2022蓝桥杯模拟赛 python_如果一个整数的某个款位包含2,则務这个 敗为一个最2政字,今如:102. 2022都是最2数

如果一个整数的某个款位包含2,则務这个 敗为一个最2政字,今如:102. 2022都是最2数

1.

  1. 以下是一个 2525 列的字母矩阵,全部由字母 A 和 B 组成。
  2. AAAAAAABABBAABABABAAAAAAA
  3. ABBBBBABBAABBBBBABABBBBBA
  4. ABAAABABBBABAABBBBABAAABA
  5. ABAAABABBBBBAABAABABAAABA
  6. ABAAABABBABABBABABABAAABA
  7. ABBBBBABBBABAABBBBABBBBBA
  8. AAAAAAABABABABABABAAAAAAA
  9. BBBBBBBBABAABABBBBBBBBBBB
  10. AABAABABBAAABBAAABABBBBBA
  11. ABBABABBBABBAAAABBBBAAAAB
  12. BBBBAAABABAABABAABBBAABBA
  13. BBAABABABAAAABBBAABBAAAAA
  14. ABABBBABAABAABABABABBBBBA
  15. AAAABBBBBABBBBAAABBBABBAB
  16. AABAABAAABAAABAABABABAAAA
  17. ABBBBBBBBABABBBBABAABBABA
  18. ABBBAAABAAABBBAAAAAAABAAB
  19. BBBBBBBBABBAAABAABBBABBAB
  20. AAAAAAABBAAABBBBABABAABBA
  21. ABBBBBABBAABABAAABBBABBAA
  22. ABAAABABABBBAAAAAAAAAABAA
  23. ABAAABABABABBBABBAABBABAA
  24. ABAAABABBABBABABAABAABAAA
  25. ABBBBBABABBBBBABBAAAABAAA
  26. AAAAAAABAABBBAABABABBABBA
  27. 请问在这个矩阵中有多少个字母A?
  1. s=open('C:\\Users\\10698\\Desktop\\test.txt')
  2. f=list(s)
  3. res=[]
  4. for i in range(len(f)):
  5. res+=f[i]
  6. print(res.count('A'))
  1. num=[]
  2. cnt=0
  3. with open('22.txt') as f:
  4. for line in f.readlines():
  5. for i in range(len(line)):
  6. if line[i]=='A':
  7. cnt+=1
  8. print(cnt)

2.

  1. 如果一个整数的某个数位包含 2 ,则称这个数为一个“最2数字”。例如:1022021 都是最2数字。
  2. 请问在 1(含) 到 2021(含) 中,有多少个最2数字。
  1. res=0
  2. for i in range(1,2022):
  3. c=i
  4. while c:
  5. a=c%10
  6. if a==2:
  7. res+=1
  8. break
  9. c//=10
  10. print(res)

寻找2020

  1. nums=[]
  2. with open('2020.txt') as f:
  3. for line in f.readlines():
  4. nums.append(list(line.strip()))
  5. res = 0
  6. for i in range(len(nums)):
  7. for j in range(len(nums)-3):
  8. if nums[i][j] == '2' and nums[i][j+1] == '0' and nums[i][j+2] == '2' and nums[i][j+3] == '0':
  9. res +=1
  10. for i in range(len(nums)-3):
  11. for j in range(len(nums)):
  12. if nums[i][j] == '2' and nums[i+1][j] == '0' and nums[i+2][j] == '2' and nums[i+3][j] == '0':
  13. res += 1
  14. for i in range(len(nums)-3):
  15. for j in range(len(nums)-3):
  16. if nums[i][j] == '2' and nums[i+1][j+1] == '0' and nums[i+2][j+2] == '2' and nums[i+3][j+3] == '0':
  17. res += 1
  18. print(res)

数列求值

  1. a=[0 for i in range(20190324+5)]
  2. a[1]=1
  3. a[2]=1
  4. a[3]=1
  5. for i in range(4,20190324+1):
  6. a[i]=(a[i-1]+a[i-2]+a[i-3])%10000
  7. print(a[20190324])

平方和

  1. N=2019
  2. num=[]
  3. for a in range(1,N+1):
  4. b=a
  5. while b:
  6. c=b%10
  7. if c==2 or c==0 or c==1 or c==9:
  8. num.append(a)
  9. break
  10. b//=10
  11. #print(sum(num))
  12. cnt=0
  13. for i in range(len(num)):
  14. cnt+=num[i]*num[i]
  15. print(cnt)

单词分析

  1. s=input()
  2. cnt=[0 for i in range(26)]
  3. for i in range(len(s)):
  4. cnt[ord(s[i])-ord('a')]+=1
  5. maxm=max(cnt)
  6. for i in range(len(s)):
  7. if cnt[i]==maxm:
  8. print(chr(ord('a')+i))
  9. break
  10. print(maxm)

约数个数

  1. n=1200000
  2. i=1
  3. cnt=0
  4. while i<=n**0.5:
  5. if n%i==0:
  6. cnt+=2
  7. i+=1
  8. if n**0.5==int(n**0.5):
  9. cnt-=1
  10. print(cnt)

成绩统计

  1. n=int(input())
  2. a=[]
  3. for i in range(n):
  4. a.append(int(input()))
  5. jige=0
  6. youxiu=0
  7. for i in range(n):
  8. if a[i]>=60:
  9. jige+=1
  10. if a[i]>=85:
  11. youxiu+=1
  12. print("%d%%"%(round(jige/n*100)))
  13. print("%d%%"%(round(youxiu/n*100)))

跑步锻炼

  1. from datetime import date,timedelta
  2. ed=date(2020,10,1)#结束日期
  3. st=date(2000,1,1)#开始日期
  4. res=0
  5. while st<=ed:
  6. if st.day==1 or st.weekday()==0:#或者用st.isoweekday()==1
  7. res+=2
  8. else:
  9. res+=1
  10. st+=timedelta(days=1)
  11. print(res)

成绩分析

  1. a=[]
  2. n=int(input())
  3. for i in range(n):
  4. a.append(int(input()))
  5. summ=sum(a)
  6. maxm=max(a)
  7. minm=min(a)
  8. print(maxm)
  9. print(minm)
  10. print("%.2f"%(summ/n))

平面分割

  1. m=20
  2. n=20
  3. cnt=m*m+n*n*0.5+2*m*n-m+0.5*n+1
  4. print(int(cnt))

蛇形填数

  1. a=20
  2. b=20
  3. summ=0
  4. c=a+b-1
  5. for i in range(1,c+1):
  6. summ+=i
  7. cnt=0
  8. if summ%2==0: #最后一个数为偶数
  9. cnt=summ-b+1
  10. else: #最后一个数为奇数
  11. cnt=summ-a+1
  12. print(cnt)

既约分数

  1. def gcd(a, b):
  2. return a if b == 0 else gcd(b, a % b)
  3. ans = 0
  4. for zi in range(1, 2021):
  5. for mu in range(1, 2021):
  6. if gcd(zi, mu) == 1:
  7. ans += 1
  8. print(ans)

门牌制作

  1. x=[i for i in range(1,2021)]
  2. cnt=0
  3. for y in x:
  4. j=y
  5. while j:
  6. a=j%10
  7. if a==2:
  8. cnt+=1
  9. j//=10
  10. print(cnt)

方程整数解

  1. try:
  2. while True:
  3. n=int(input())
  4. len=int(n**0.5)
  5. flag=0
  6. for a in range(1,len+1):
  7. for b in range(a,len+1):
  8. for c in range(b,len+1):
  9. if a*a+b*b+c*c==n:
  10. print("%d %d %d"%(a,b,c))
  11. flag=1
  12. if flag==0:
  13. print("No Solution")
  14. except:
  15. pass

最大降雨量

注意读题,求的不是七周中位数的和,而是七周中位数的中位数的最大值

如图

a,b,c,x,e,f,g分别是每周的中位数。

而x是a,b,c,x,e,f,g是这七周的每一周的中位数的中位数

题目的要求是让我们最大化这个x;

我们可以假定x已经是我们要求的值,那么为了让x符合题目信息,我们必须让第4周的后3天,第5,6,7周的后4天都大于这个值。

那么很显然有15个数比x大,那么x就等于49 - 15 = 34;

年号字串

  1. n = 2019
  2. s = ''
  3. while n > 0:
  4. n -= 1
  5. a, b = n//26, n%26
  6. s += chr(b+ord('A'))
  7. n = a
  8. print(s[::-1])

组队

  1. num=[]
  2. with open('team.txt') as f:
  3. for line in f.readlines():
  4. num.append(list(line.split()))
  5. flag=[0 for i in range(len(num)+1)]
  6. ssum=0
  7. maxx=0
  8. last=0
  9. for i in range(len(num)):
  10. if int(num[i][1])>maxx and flag[i]==0:
  11. maxx=int(num[i][1])
  12. flag[last]=0
  13. flag[i]=1
  14. last=i
  15. ssum+=maxx
  16. maxx=0
  17. last=0
  18. for i in range(len(num)):
  19. if int(num[i][2])>maxx and flag[i]==0:
  20. maxx=int(num[i][2])
  21. flag[last]=0
  22. flag[i]=1
  23. last=i
  24. ssum+=maxx
  25. maxx=0
  26. last=0
  27. for i in range(len(num)):
  28. if int(num[i][3])>maxx and flag[i]==0:
  29. maxx=int(num[i][3])
  30. flag[last]=0
  31. flag[i]=1
  32. last=i
  33. ssum+=maxx
  34. maxx=0
  35. last=0
  36. for i in range(len(num)):
  37. if int(num[i][4])>maxx and flag[i]==0:
  38. maxx=int(num[i][4])
  39. flag[last]=0
  40. flag[i]=1
  41. last=i
  42. ssum+=maxx
  43. maxx=0
  44. last=0
  45. for i in range(len(num)):
  46. if int(num[i][5])>maxx and flag[i]==0:
  47. maxx=int(num[i][5])
  48. flag[last]=0
  49. flag[i]=1
  50. last=i
  51. ssum+=maxx
  52. maxx=0
  53. last=0
  54. print(ssum)

特别数的和

  1. N=int(input())
  2. ssum=0
  3. for i in range(1,N+1):
  4. a=i
  5. while a:
  6. b=a%10
  7. if b==2 or b==0 or b==1 or b==9:
  8. ssum+=i
  9. break
  10. a//=10
  11. print(ssum)

[蓝桥杯2019初赛]数的分解

  1. def check(a):
  2. while a:
  3. b=a%10
  4. if b==2 or b==4:
  5. return 0
  6. a//=10
  7. return 1
  8. cnt=0
  9. for i in range(1,2019+1):
  10. for j in range(i+1,2019+1):
  11. k=2019-i-j
  12. if i<j and j<k and check(i) and check(j) and check(k):
  13. cnt+=1
  14. print(cnt)

[蓝桥杯2019初赛]数的分解

  1. n=int(input())
  2. a=list(map(int,input().split()))
  3. j=1
  4. deep=1
  5. ff=0
  6. maxx=0
  7. i=0
  8. while i<n:
  9. b=[]
  10. for k in range(j):
  11. if i+k<n:
  12. b.append(a[i+k])
  13. else:
  14. break
  15. #print(b)
  16. if sum(b)>maxx:
  17. maxx=sum(b)
  18. ff=deep
  19. i+=j
  20. j*=2
  21. deep+=1
  22. print(ff)

[蓝桥杯2019初赛]矩形切割

  1. a=2019
  2. b=324
  3. cnt=0
  4. while a and b:
  5. cnt+=1
  6. a=a-b
  7. a,b=max(a,b),min(a,b)
  8. print(cnt)

质数

  1. from math import sqrt
  2. def check(n):
  3. i=2
  4. while i<=sqrt(n):
  5. if n%i==0:
  6. return 0
  7. i+=1
  8. return 1
  9. cnt=1 #2是第一个质数,偶数
  10. i=3
  11. while True:
  12. if check(i):
  13. cnt+=1
  14. if cnt==2019:
  15. print(i)
  16. break
  17. i+=2

[蓝桥杯2019初赛]旋转

  1. m,n=map(int,input().split())
  2. a=[]
  3. for i in range(m):
  4. a.append(list(map(int,input().split())))
  5. #找规律
  6. # (1,1)->(1,3) (1,2)->(2,3) (1,4)->(4,3)
  7. # (2,1)->(1,2) ... (2,4)->(4,2)
  8. # (3,1)->(1,1) ... (3,4)->(4,1)
  9. # (2,2)->(2,2) (2,3)->(3,2)
  10. # m=3,n=4 顺时针90度,行=原来的列,列=n-原来的行
  11. b=[[0 for i in range(m)] for i in range(n)]
  12. for i in range(m):
  13. for j in range(n):
  14. b[j][m-1-i]=a[i][j]
  15. for i in range(n):
  16. for j in range(m):
  17. print(b[i][j],end=" ")
  18. print()

[蓝桥杯2019初赛]最短路

  1. g=[[float('inf') for i in range(26)] for j in range(26)]
  2. st=[0 for i in range(26)]
  3. n=19 #共有19个点
  4. def dijkstra():
  5. dist=[float('inf') for i in range(26)]
  6. dist[1]=0
  7. for i in range(n):
  8. t=-1
  9. for j in range(1,n+1):
  10. if (not st[j]) and (t==-1 or dist[t]>dist[j]):
  11. t=j #核心,加入当前未加入中距离最小的点
  12. for j in range(1,n+1): #每次加入一个点,更新值
  13. dist[j]=min(dist[j],dist[t]+g[t][j])
  14. st[t]=1
  15. return dist[19]
  16. def add(a,b,c):
  17. g[a][b]=c
  18. g[b][a]=c
  19. #输入距离
  20. add(1,2,2)
  21. add(1,3,1)
  22. add(1,4,1)
  23. add(1,5,1)
  24. add(2,7,1)
  25. add(2,10,2)
  26. add(3,6,3)
  27. add(3,7,3)
  28. add(3,4,3)
  29. add(4,5,1)
  30. add(4,7,2)
  31. add(4,8,1)
  32. add(4,9,2)
  33. add(5,8,1)
  34. add(5,9,3)
  35. add(6,7,1)
  36. add(6,10,1)
  37. add(7,9,3)
  38. add(7,11,2)
  39. add(8,9,1)
  40. add(8,12,2)
  41. add(9,13,3)
  42. add(10,19,2)
  43. add(11,12,3)
  44. add(11,14,1)
  45. add(11,16,2)
  46. add(12,13,1)
  47. add(12,18,1)
  48. add(13,17,1)
  49. add(13,19,1)
  50. add(13,14,2)
  51. add(14,16,1)
  52. add(15,16,1)
  53. add(15,17,1)
  54. add(15,18,3)
  55. add(18,19,1)
  56. #迪杰斯特拉模板再背一遍
  57. print(dijkstra())

字串数字

  1. n="LANQIAO"
  2. ssum=0
  3. for i in range(len(n)):
  4. ssum+=(ord(n[i])-ord('A')+1)*pow(26,len(n)-1-i)
  5. print(ssum)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/73626
推荐阅读
相关标签
  

闽ICP备14008679号