Created
March 25, 2019 16:16
-
-
Save malkoG/c9a502a02f6af7f9f463f1f574db7c6a to your computer and use it in GitHub Desktop.
noj.am/6642
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def translate(dotted_cash): | |
over_dot, under_dot = map(int, dotted_cash.split(".")) | |
return over_dot * 100 + under_dot | |
output = [] | |
while True: | |
n=int(input()) | |
bank = dict() | |
if n == 0: | |
output.append("goodbye") | |
break | |
for i in range(n): | |
account, cash = input().split() | |
bank[account] = translate(cash) | |
while True: | |
command=input().split() | |
if command[0] == "end": | |
output.append("end") | |
output.append("") | |
input() | |
break | |
if command[0] == "create": | |
_, account = command | |
try: | |
if bank[account] >= 0: | |
output.append("create: already exists") | |
except KeyError: | |
bank[account] = 0 | |
output.append("create: ok") | |
elif command[0] == "deposit": | |
_, account, cash = command | |
try: | |
bank[account] += translate(cash) | |
output.append("deposit {}: ok".format(cash)) | |
except KeyError: | |
output.append("deposit {}: no such account".format(cash)) | |
elif command[0] == "withdraw": | |
_, account, cash = command | |
try: | |
translated_cash = translate(cash) | |
if bank[account] < translated_cash: | |
output.append("withdraw {}: insufficient funds".format(cash)) | |
else: | |
bank[account] -= translated_cash | |
output.append("withdraw {}: ok".format(cash)) | |
except KeyError: | |
output.append("withdraw {}: no such account".format(cash)) | |
else: | |
_, source, target, cash = command | |
translated_cash = translate(cash) | |
try: | |
_ = bank[source], bank[target] | |
if source == target: | |
output.append("transfer {}: same account".format(cash)) | |
elif bank[source] < translated_cash: | |
output.append("transfer {}: insufficient funds".format(cash)) | |
else: | |
bank[source] -= translated_cash | |
bank[target] += translated_cash | |
if source[-1] != target[-1]: | |
output.append("transfer {}: interbank".format(cash)) | |
else: | |
output.append("transfer {}: ok".format(cash)) | |
except KeyError: | |
output.append("transfer {}: no such account".format(cash)) | |
print("\n".join(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment