华为机试330分python实现

转载声明:本文是本人原创。其他人转载请注明来源(CSDN)附url地址。本人保留追究一切法律责任的权利,谢谢。

Copyright © 2021 XiaoPeng. All rights reserved.

第一题100分,代码完成100%

1,有几种上班状态,迟到,早退,正常上班,缺勤。
满足以下三种情况无法得到全勤奖:
1,缺勤超过两次。
2,连续迟到早退超过三次。
3,连续七次迟到早退缺勤超过三次。
能得全勤奖,打印true。得不到全勤奖,打印false。

while True:
    try:
        n = int(input())
        absent_flag = False
        late_flag = False
        total_flag = False
        for i in range(n):
            recordlist = input().split()
            absent_num = recordlist.count("absent")
            if absent_num>=2:
                absent_flag = True
            else:
                absent_flag = False
            for i in range(len(recordlist)-1):
                if (recordlist[i] == 'late' or recordlist[i] =="leaveearly") and (recordlist[i+1] == 'late' or recordlist[i+1] =="leaveearly"):
                    late_flag = True
                if i < len(recordlist)-7:
                    rec_list = recordlist[i:i+7]
                    total_num = rec_list.count("late")+rec_list.count("absent")+rec_list.count("leaveearly")
                    if total_num >=4:
                        total_flag = True
            if absent_flag or late_flag or total_flag:
                print("false",end=' ')
            else:
                print("true",end=' ')
    except:
        break

第二题100分,完成90%

输入矩阵行,列。
输入矩阵各行各列。
求矩阵内子矩阵的和最大值。

#输入
#3 4
#-3 3 -1 4
#-4 4 -2 5
# 5 5 -3 3
#输出
#18 

while True:
    try:

        row,col = map(int,input().split())
        if row == 0 or col == 0:
            print(0)
            break
        L = []
        for i in range(row):
            LL = list(map(int,input().split()))
            L.append(LL)
        L_max_sum = 0
        num_sum = 0
        for  pos_row in range(row):
            for pos_col in range(col):

                row_yu = row - pos_row
                col_yu = col - pos_col
                for i_row_yu in range(row_yu):
                    for i_col_yu in range(col_yu):
                        num_sum = 0
                        for row_num in range(i_row_yu+1):
                            for col_num in range(i_col_yu+1):
                                num_sum += L[pos_row+row_num][pos_col+col_num]
                        if L_max_sum < num_sum:
                            L_max_sum = num_sum
        print(L_max_sum)
    except:
        break

第三大题200分,完成70%

有一种游戏,每个人手上有一些不同颜色和数字的卡牌。上一个人发玩牌后,下一个人可以出同样的颜色和数字。下面第一行输入数字,第二行输入颜色,请输出最优策略可以打出牌的数量。

#输入
#1 4 3 4 5
#r y b b r
#输出 
#3
while True:
    try:
        num_list = list(map(int, input().split()))
        color_list = input().split()
        max_num = 0
        num = 0
        for i in range(len(num_list)):
            if num_list.count(num_list[i]) == 1:
                num = color_list.count(color_list[i])
            elif num_list.count(num_list[i]) >= 2:
                num = color_list.count(color_list[i])
                for j in range(i + 1, len(num_list)):
                    if num_list[i] == num_list[j]:
                        if color_list[i] == color_list[j]:
                            pass
                        else:
                            num += color_list.count(color_list[j])
            if max_num < num:
                max_num = num
        print(max_num)
    except:
        break
  • 6
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FPGA技术指导

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值