第十一届蓝桥杯大赛第二场省赛试题------蓝桥杯Python大学组

目录

A

B

C


欢迎互相交流学习

A

count = 0
for i in range(1, 2021):
    j = str(i)
    if '2' in j:
        count += 1
print(count)
# 563






B

# import random
#
# # 定义矩阵的行数和列数
# rows = 500
# cols = 400
#
# a = 0
# # 随机生成2和0的矩阵
# matrix = [[random.choice([2, 0]) for _ in range(10)] for _ in range(8)]
#
# # 将矩阵写入文件
# with open('2020.txt', 'w') as file:
#     for row in matrix:
#         file.write(' '.join(map(str, row)) + '\n')
#
# print("矩阵已写入到2020.txt文件中。")
#
# 打开文件并读取内容
with open('2020.txt', 'r') as file:
    # 逐行读取文件内容并将每行拆分成整数,形成一个二维列表
    matrix = [list(map(int, line.strip().split())) for line in file]
row = len(matrix)
col = len(matrix[0])
# 现在,matrix1 包含了从文件中读取的内容
print(matrix)
print(row)
print(col)
count = 0
for i in range(0, row - 3):
    for j in range(0, col - 3):
        if matrix[i][j] == 2 and matrix[i+1][j+1] == 0 and matrix[i+2][j+2] == 2 and matrix[i+3][j+3] == 0:
            count += 1
        if matrix[i][j] == 2 and matrix[i][j+1] == 0 and matrix[i][j+2] == 2 and matrix[i][j+3] == 0:
            count += 1
        if matrix[i][j] == 2 and matrix[i+1][j] == 0 and matrix[i+2][j] == 2 and matrix[i+3][j] == 0:
            count += 1
print(count)




C

# from 2000年1月1日周六 to 2020年10月1日周四
# 1 3 5 7 8 10 12 31天
# 4 6 9 11 30天
# 2 闰年 29 平年 28
year = 2000
month = 1
day = 1
week = 6
count = 0
while 1:
    count += 1
    if day == 1 or week == 1:
        count += 1
    #      到达日期跳出循环
    if year == 2020 and month == 10 and day == 1:
        break
    #     week增加部分
    if week == 7:
        week = 1
    else:
        week += 1
    #     年月份增加部分
    if month in [1, 3, 5, 7, 8, 10, 12]:
        if day == 31:
            day = 1
            if month == 12:
                month = 1
                year += 1
            else:
                month += 1
        else:
            day += 1
    if month in [4, 6, 9, 11]:
        if day == 30:
            day = 1
            month += 1
        else:
            day += 1
    if month == 2:
        if year % 4 == 0:
            if day == 29:
                day = 1
                month = 3
            else:
                day += 1
        else:
            if day == 28:
                day = 1
                month = 3
            else:
                day += 1
print(count)
# 8667




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值