Python解答第十届蓝桥杯大赛个人赛软件类C

  1. 求和

    个人赛软件类B

  2. 矩形切割

    problemCC03

    mat = [2019, 324]
    # mat = [5, 3]
    count = 0
    while mat[0] >= 1 and mat[1] >= 1:
        mat[mat.index(max(mat))] = max(mat) - min(mat)
        count += 1
    print(count)  # 21
    
  3. 年号字串

    个人赛软件类B

  4. 质数

    problemCC05

    def is_prim(n):
        if n == 1:
            return False
        for i in range(2, n):
            if n % i == 0:
                return False
        return True
    
    
    ans = 0
    i = 1
    while i <= 2019:
        if is_prim(i):
            ans += 1
        i += 1
    
    print(ans)  # 306
    
    
  5. 最大降雨量

    个人赛软件类A

  6. 旋转A

    problemCC07

    n, m = list(map(int, input().split()))
    fig = [list(map(int, input().split())) for i in range(n)]
    new_fig = [[0 for i in range(n)] for i in range(m)]
    
    for i in range(m):
        for j in range(n):
            new_fig[i][j] = fig[n-j-1][i]
    
    for i in range(m):
        print(*new_fig[i])
    """
    3 4
    1 3 5 7
    9 8 7 6
    3 5 9 7
    """
    
  7. 外卖店优先级

    个人赛软件类A

  8. 人物相关性分析

    problemCC11

    import re
    k = int(input())
    s = input()
    ans = 0
    pattern = '\WAlice\W|\WBob\W' # 占了两个符位
    
    while True:
        start = re.search(pattern, s).end()  # 第一个Alice 或 Bob的末尾索引
        name = re.search(pattern, s).group()
        name = re.search('\w+', name).group()  # 确定是Alice 还是 Bob
        s = s[start:]  # 检查过的第一部分丢掉,第二部分保留,因为下次还要用。
        if re.search(pattern, s):  # 能找到,找不到也就是没有Alice或者bob与前一个Alice或Bob匹配
            other = re.search(pattern, s).group()
            other = re.search('\w+', other).group() # 确定紧接着的是Alice 还是 Bob
            if name != other:  # 名字不同才进行
                end = re.search(pattern, s).start()  # 此时other对应的起始位置就是和上一个name直接的距离-2,因为模式有两个占位
            else:
                end = k + 1  # 名字相同不行 设置间距为比k大的数, 比如Bob love Bob ,我们要检测的是Bob ... Alice 或 Alice ... Bob
        else:
            # 如果剩下的s没有Alice或Bob则结束循环
            break
        if end + 2 <= k:  # pattern = '\WAlice\W|\WBob\W' # 占了两个符位
            ans += 1
    
    print(ans)
    """
    20
    This is a story about Alice and Bob. Alice wants to send a private message to Bob. Bob love Alice.
    3
    """
    
  9. 等差数列

    个人赛软件类B

  10. 扫地机器人

    待上传

猜你喜欢

转载自blog.csdn.net/qq_31910669/article/details/109028695