goods = [
['农夫山泉', 2, 10],
['怡宝', 2, 10],
['冰红茶', 3, 10],
['可口可乐', 3, 10],
['脉动', 4, 10],
['红牛', 6, 10]
]
coins = [
[1, 10],
[2, 10],
[5, 10],
[10, 10]
]
balance = 0
GoodsName = []
for i in goods:
GoodsName.append(i[0])
def sumMycoin(li,type=list):
sum_1 = 0
for i in li:
sum_1 += i
return sum_1
def sorted_by_count_price(x):
return x[2],x[0]
def initial():
initialValue = input()
initialValue_list = initialValue.split(" ")
if initialValue_list[0] == 'r':
goods_count_list = initialValue_list[1].split("-")
coins_count_list = initialValue_list[2].split("-")
for i in range(6):
if int(goods_count_list[i]) < 11 and int(goods_count_list[i]) >= 0:
goods[i][2] = int(goods_count_list[i])
else:
if int(goods_count_list[i]) < 0:
goods_count_list[i] = 0
elif int(goods_count_list[i]) > 10:
goods_count_list[i] = 10
else:
print("error")
for i in range(4):
if int(coins_count_list[i]) < 11 and int(coins_count_list[i]) >= 0:
coins[i][1] = int(coins_count_list[i])
else:
if int(coins_count_list[i]) < 0:
coins_count_list[i] = 0
elif int(coins_count_list[i]) > 10:
coins_count_list[i] = 10
else:
print("error")
print(goods, coins)
print("S001:Initialization is successful")
coins_sum = []
def Paycoin():
global balance
goods_count = 0
coins_values = [1,2,5,10]
CoinValue = Command
CoinValue_list = CoinValue.split(" ")
if int(CoinValue_list[1]) in [1, 2, 5, 10]:
balance = int(CoinValue_list[1])
coins_sum.append(int(CoinValue_list[1]))
coins[coins_values.index(int(CoinValue_list[1]))][1] += 1
if coins[0][1] * 1 + coins[1][1] * 2 < balance :
print("E003:Change is enough,pay fail")
coins_sum.pop()
else:
if balance > 10:
print("E004:Pay the balance is beyond the scope biggest")
coins_sum.pop()
else:
for i in range(6):
goods_count += goods[i][2]
if goods_count == 0:
print("E005:All the goods sold out")
coins_sum.pop()
else:
print("S002:Pay success,balance=%d" %(sumMycoin(coins_sum)))
elif int(CoinValue_list[1]) not in [1, 2, 5, 10]:
print("E002:Denomination error")
BuySpend = []
def buyGoods():
GoodsNeed = Command
GoodsNeed_list = GoodsNeed.split(" ")
print(GoodsNeed_list)
for i in goods:
if GoodsNeed_list[1] not in GoodsName:
print(GoodsNeed_list[1])
print(i)
print("E006:Goods does not exist")
elif GoodsNeed_list[1] == i[0]:
GoodsInfo = i
if GoodsInfo[2] == 0:
print("E007:The goods sold out")
else:
if GoodsInfo[1] > sumMycoin(coins_sum):
print("E008:Lack of balance")
else:
coins_sum.append(-GoodsInfo[1])
BuySpend.append(GoodsInfo[1])
print("S003:Buy success,balance=%d" % (sumMycoin(coins_sum)))
Coin_return = []
for i in range(4):
Coin_return.append([coins[i][0],0])
def returnCoin():
if sumMycoin(coins_sum) == 0:
print("E009:Work failure")
elif sumMycoin(coins_sum) > 0:
for i in range(4)[::-1]:
if coins[i][0] <= sumMycoin(coins_sum) and coins[i][1] > 0:
coins[i][1] -= 1
coins_sum.append(-coins[i][0])
Coin_return[i][1] += 1
for i in range(3):
print("%d yuan coin number=%d" %(Coin_return[i][0],Coin_return[i][1]))
print("%d yuan coin number=%d" % (Coin_return[3][0], Coin_return[3][1]))
def queryGoods():
goodsInfo = Command_list
if goodsInfo[1] == '0':
goodsSorted = sorted(goods,key = sorted_by_count_price)
for i in goodsSorted:
print("%s\t%d\t%d" %(i[0],i[1],i[2]))
elif goodsInfo[1] == '1':
for i in range(3):
print("%d yuan coin number=%d" %(coins[i][0],coins[i][1]))
print("%d yuan coin number=%d" % (coins[3][0], coins[3][1]))
else:
print("E010:Parameter error")
initial()
while True:
Command = input()
print(Command)
Command_list = Command.split(" ")
if Command_list[0] == 'p':
Paycoin()
elif Command_list[0] == 'b':
buyGoods()
elif Command_list[0] == 'c':
returnCoin()
elif Command_list[0] == 'q':
queryGoods()