第十一届蓝桥杯大赛第二场省赛试题C&C++ 大学B组真题 python实现

第十一届蓝桥杯大赛第二场省赛试题C&C++ 大学B组真题 python实现,第1张

第十一届蓝桥杯大赛第二场省赛试题C&C++ 大学B组真题 python实现

目录

A.门牌制作B.既约分数C.蛇形填数D.跑步锻炼E.七段码F.成绩统计G.回文日期H.字串分值和I.平面切分J.字串排序

A.门牌制作


代码

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

答案: 624

B.既约分数


代码:

num = 0
# 辗转相除
def func(a, b):
	x = a % b
	while x != 0:
		a = b
		b = x
		x = a % b
	return b

for i in range(1, 2021):
	for j in range(1, 2021):
		if func(i, j) == 1:
			num += 1
print(num)
	

答案:2481215

C.蛇形填数


代码:

dir = 0  # 0代表向右,1代表向下
a = [[0 for i in range(100)] for j in range(100)]
x, y = 0, 0
num = 1
while True:
    if x == 19 and y == 19:
        break
    while dir == 0:
        x, y = x, y+1
        num += 1
        while y != 0:
            x += 1
            y -= 1
            num += 1
            if x == 19 and y == 19:
                print(num)
                break
        dir = 1
    while dir == 1:
        x, y = x+1, y
        num += 1
        while x != 0:
            x -= 1
            y += 1
            num += 1
            if x == 19 and y == 19:
                print(num)
                break
        dir = 0

答案: 761

D.跑步锻炼


代码:

year = 2000
month = 1
day = 1
week = 6
res = 0
dateday = [0,31,28,31,30,31,30,31,31,30,31,30,31]

# 闰年判断
def run(year):
        if year % 4 == 0 and year % 100 != 0:
                return True
        elif year % 400 == 0:
                return True
        else:
                return False

while year != 2020 or month != 10 or day != 1:
        if run(year):
                dateday[2] = 29
        else:
                dateday[2] = 28
        day += 1

        week = (week+1)%7

        if day > dateday[month]:
                day = 1
                month += 1
        if month > 12:
                month = 1
                year += 1
        if day == 1 or week == 1:
                res += 1
        res += 1
res += 2
print(res)

答案: 8879

E.七段码


代码:

这个可以数发光的个数:
1 : 7种
2: 10种
3: 16种
4: 20种
5: 19种
6: 7种
7: 1种
ans = 7 + 10 + 16 + 20 + 19 + 7 + 1 = 80
一共80种
F.成绩统计




代码:

n = int(input())
num1 = 0
num2 = 0
for i in range(n):
    stu = int(input())
    if stu >= 60:
        num1 += 1
    if stu >= 85:
        num2 += 1
print('{:d}%'.format(round(num1/n*100)))
print('{:d}%'.format(round(num2/n*100)))

G.回文日期




代码:

from calendar import isleap
n = int(input())

def check(year):
    month = int(year[:2])
    day = int(year[2:4])
    year = int(year)
    if 1 <= month <= 12:
        if month == 2:
            if isleap(year):
                if day <= 29:
                    return True
                else:
                    return False
            else:
                if day <= 28:
                    return True
                else:
                    return False
        if month in [1,3,5,7,8,10,12]:
            if day <= 31:
                return True
            else:
                return False
        else:
            if day <= 30:
                return True
            return False
    return False
arr1 = []
arr2 = []
for i in range(1000, 9999):
    x1 = str(i)[::-1]
    x2 = (str(i)[:2]+str(i)[:2])[::-1]
    if check(x1) and int(x1[::-1]+x1)>n:
        arr1.append(int(x1[::-1]+x1))
    if check(x2) and int(x2[::-1]+x2)>n:
        arr2.append(int(x2[::-1]+x2))

print(arr1[0])
print(arr2[0])
H.字串分值和




代码:
暴力解法肯定不能ac,大概50%是可以过的

s = input()
n = len(s)
res = 0
left = 0
right = 0
while left < n:
    if right == n:
        left += 1
        right = left
    right += 1
    s_ = set(s[left:right])
    res += len(s_)
print(res)
I.平面切分


代码:

n = int(input())
li = []
for i in range(n):
    li.append(list(map(int, input().split())))
res = 2 
node = []
for i in range(1, n):
    for j in range(i):
      if li[i][0] != li[j][0]:
        x = (li[i][1] - li[j][1]) / (li[j][0] - li[i][0])
        y = li[j][0] * x + li[j][1] 
        if [x, y] in node:
            pass
        else:
            node.append([x, y]) 
    res += len(node) + 1
    node = []
print(res)
J.字串排序




这道题emmmm就这样吧 大体就是dfs的思路

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5713665.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存