huaweiOD机试题 人气最高店铺 Python

本质是让其余店铺要叛变,代码如下。

n,m=map(int,input().split(","))
li=[]
for i in range(n):
    s=list(map(int,input().split(",")))
    li.append(s)
li_name=[]
li_money=[]
for i in range(len(li)):
    if li[i][0]!=1:
        li_name.append(li[i][0])
        li_money.append(li[i][1])
num_1=len(li)-len(li_name)
re=[0]
print(li_money)
print(li_name)
def fun(re,num_1,li_name,li_money):
    count_x=0
    for i in range(len(li_name)):
        if li_name.count(li_name[i])>count_x:
            count_x=li_name.count(li_name[i])
    if num_1>count_x:
        return
    elif num_1==count_x:
        re.append(min(li_money))
        return
    else:
        temp=[]
        for i in range(len(li_name)):
            if count_x==li_name.count(li_name[i]):
                temp.append(i)
        li_money_new=sorted(li_money)
        min_money=li_money[temp[0]]
        li_temp=[temp[0]]
        for i in range(1,len(temp)):
            if li_money[temp[i]]=min_money:
            li_money.pop(li_temp[-1])
            li_name.pop(li_temp[-1])
            num_1+=1
            re.append(min_money)
        else:
            num_1+=1
            re.append(li_money_new[0])
            li_name.pop(li_money.index(min(li_money)))
            li_money.remove(min(li_money))
        fun(re,num_1,li_name,li_money)
fun(re,num_1,li_name,li_money)
print(str(sum(re)))

你可能感兴趣的:(python,java,前端)