小美正在设计美团外卖的定价信息。已知外卖定价的规则如下:
1. 每道菜有折扣价和原价。折扣价不能超过原价。
2. 订单有满
元减
元的优惠。当购买的菜的价格总和不小于
元时,总价格可以减
元。“减”的价格不能超过“满”的价格。
3. 满减优惠和折扣价是互斥的,当且仅当每个菜都选择了原价才可以触发满减。
4. 系统会自动为客户计算最低价格的方案。
请使用等价划分法设计测试用例,来测试该系统的功能。
第一行输入一个正整数,代表菜的总数。
接下来的行,每行输入两个实数
和
,代表每道菜的原价是
,折扣价是
。
最后一行输入两个实数和
,代表满
元可以减
元。
数据中所有实数的绝对值不超过1000。
如果数据有误,则输出一行字符串"error"。
否则输出一个小数,小数点后保留2位即可。该小数代表顾客购买了全部菜各一份时,订单的总价格。
2 10 5.5 10 6.5 15 3
12.00
虽然触发了满15元减3元,但使用折扣只需要花12元,低于使用满减的价格(20-3=17),因此最终系统会为客户推荐折扣价。
2 10 5.5 10 6.5 20 10
10.00
触发满20元减10元即可。满减价优于折扣价。
2 10 10.25 10 3.5 20 4.5
error
折扣价高于原价,数据错误。
import sys
price = []
count_price = []
number = 0
for i, line in enumerate(sys.stdin):
a = line.split()
if i == 0:
number = int(a[0])
else:
if float(a[0]) < float(a[1])&nbs***bsp;float(a[0])<=0&nbs***bsp;float(a[1]) <= 0: # 折扣价大于原价
print("error")
exit()
price.append(float(a[0]))
count_price.append(float(a[1]))
total_price1 = sum(price[:-1])
if total_price1 >= price[-1]:
total_price1 -= count_price[-1]
total_price2 = sum(count_price[:-1])
print("%.2f"%min(total_price1, total_price2)) def sol(ori,dis,x,y):
sumDis = sum(dis)
sumOri = sum(ori)
if sumOri>=x:
return min(sumDis,sumOri-y)
else:
return sumDis
while 1:
try:
n = int(input())
arr,ori,dis = [],[],[]
isContinue = True
for i in range(n):
temp = list(map(float,input().split()))
if temp[0]<temp[1]&nbs***bsp;temp[0]<=0&nbs***bsp;temp[1]<=0:
print('error')
isContinue = False
break
arr.append(temp)
ori.append(temp[0])
dis.append(temp[1])
x,y = map(float,input().split())
if x<y&nbs***bsp;x<=0&nbs***bsp;y<=0:
print('error')
isContinue = False
break
if isContinue:
ans = sol(ori,dis,x,y)
print("%.2f" % ans)
except:
break 添加一个python代码版本 n = int(input())
price, discount = [], []
for _ in range(n):
p, d = map(float, input().split())
if d > p or d <= 0 or p <= 0:
print("error")
exit()
price.append(p)
discount.append(d)
full, minus = map(float, input().split())
if full <= 0 or minus <= 0 or minus > full:
print("error")
exit()
if sum(price) < full:
print("{:.2f}".format(sum(discount)))
else:
ans = min(sum(price) - minus, sum(discount))
print("{:.2f}".format(ans))
import sys
a = input()
n = int(a)
t=[]
for i in range(n):
tt = list(map(float,input().strip().split()))
t.append(tt)
c = list(map(float,input().strip().split()))
def solution(n,t:list, c:list):
result = 0
sum_cost1 = 0
sum_cost2 = 0
sum_src = 0
for i in range(n):
if t[i][0] <=0&nbs***bsp;t[i][1] <= 0&nbs***bsp;t[i][0] < t[i][1] :
return -1
sum_src += t[i][0]
sum_cost1 += t[i][1]
if c[1] <= 0&nbs***bsp;c[0] < c[1]:
return -1
elif sum_src >= c[0]:
sum_src -= c[1]
sum_cost2 = sum_src
return min(sum_cost1, sum_cost2)
result = solution(n,t,c)
if result == -1:
print("error")
else:
print("%.2f"% result)