Open CerebellarTentorium opened 3 years ago
https://judge.ccclub.io/status/4e2603e3de3ad6b9957e8512e3fdd495
shop_list = [] for num in range(4): shop = input().split() shop_list.append(shop) shop_dict = {"S商店": shop_list[0], "C商店": shop_list[1], "P商店": shop_list[2], "M商店": shop_list[3] } #將輸入之商店資料整理成list後放入以商店名為key的字典 def calculate_money(shop_data):#建立一個計算價錢的函數 price = 0 discount = 100 delivery_fee = 0 rebate = 0 #建立各項參數:價錢、折扣、運費、回饋%數 if shop_data[0] == "0": return float("inf") #若貨量為零,回傳無限,這樣最後放入價錢list後再sort就會排到最後 else: price = float(shop_data[1]) #貨量不為零給定price值 if "%" in "".join(shop_data): rebate = float(shop_data[2].replace("%", "")) else: rebate = 0 #偵測到有關折扣的敘述就給予rebate折扣值 if "免" in "".join(shop_data): delivery_fee = 0 elif "%" in "".join(shop_data): delivery_fee = float(shop_data[3].replace("運費", "")) else: delivery_fee = float(shop_data[2].replace("運費", "")) #偵測到有關運費的敘述就給予delivery_fee運費值 if "打" in "".join(shop_data): all_discount = shop_data[-1].replace("滿", " ").replace("打", " ").replace("折", " ").replace(",", " ") all_discount_list = all_discount.split()#將去除中字之數字字串放入list discount_threshold = all_discount_list[0::2] discount_amount = all_discount_list[1::2]#將打折值與需花費的金額分開成兩個list discount_threshold_num = [float(num) for num in discount_threshold]#要獲得折扣所需花費金額 discount_amount_num = [float(num) for num in discount_amount]#折扣值 discount_amount_num_new = [] for num in discount_amount_num:#將折扣值全部換成二位數 if num // 10 < 1: discount_amount_num_new.append(num * 10) else: discount_amount_num_new.append(num) discount_threshold_num.append(price) discount_threshold_num_sorted = sorted(discount_threshold_num) index_of_price = discount_threshold_num_sorted.index(price) if index_of_price != 0: the_threshold_price = discount_threshold_num_sorted[index_of_price - 1] i = discount_threshold_num.index(the_threshold_price) discount = discount_amount_num_new[i] #找到折扣值 else: discount = 100 else: discount = 100 #偵測到關鍵字給予discount折扣值 money = (( price * discount / 100 ) + delivery_fee) * (100 - rebate) / 100 #將以獲得的參數丟到公式計算 return money shop_dict["S商店"] = calculate_money(shop_dict["S商店"])#將字典中每個商店的資料以定義好的函式計算商品價格 shop_dict["C商店"] = calculate_money(shop_dict["C商店"]) shop_dict["P商店"] = calculate_money(shop_dict["P商店"]) shop_dict["M商店"] = calculate_money(shop_dict["M商店"]) money_dict_values = list(shop_dict.values()) money_list = [float(num) for num in money_dict_values] money_list.sort() the_cheapest = money_list[0] lst = [list(shop_price) for shop_price in shop_dict.items()] for items in lst: if items[1] == the_cheapest: print(items[0] + " " + str(round(items[1]))) break
Wrong Answer
謝謝助教協助。
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
提交連結
https://judge.ccclub.io/status/4e2603e3de3ad6b9957e8512e3fdd495
程式碼
錯誤訊息
Wrong Answer
問題描述
謝謝助教協助。