[HackerRank] Bill Division
1075 ワード
[問題リンク]
[入力]
bill: an array of integers representing the cost of each item ordered
k: an integer representing the zero-based index of the item Anna doesn't eat
b: the amount of money that Anna contributed to the bill
[出力]
If Brian did not overcharge Anna, print Bon Appetit on a new line; otherwise, print the difference (i.e., ) that Brian must refund to Anna. This will always be an integer.
[コード]
[入力]
bill: an array of integers representing the cost of each item ordered
k: an integer representing the zero-based index of the item Anna doesn't eat
b: the amount of money that Anna contributed to the bill
[出力]
If Brian did not overcharge Anna, print Bon Appetit on a new line; otherwise, print the difference (i.e., ) that Brian must refund to Anna. This will always be an integer.
[コード]
import math
import os
import random
import re
import sys
#
# Complete the 'bonAppetit' function below.
#
# The function accepts following parameters:
# 1. INTEGER_ARRAY bill
# 2. INTEGER k
# 3. INTEGER b
#
def bonAppetit(bill, k, b):
# Write your code here
total = 0
for i in range(len(bill)):
if(i!=k):
total += bill[i]
total = total // 2
if(total == b):
print('Bon Appetit')
else:
print(abs(total - b))
Reference
この問題について([HackerRank] Bill Division), 我々は、より多くの情報をここで見つけました https://velog.io/@jongmin97/HackerRank-Bill-Divisionテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol