Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- max_capacity = int(input())
- users = {}
- line = input()
- while not line == "Statistics":
- tokens = line.split("=")
- command = tokens[0]
- if command == "Add":
- name = tokens[1]
- sent = int(tokens[2])
- received = int(tokens[3])
- if name not in users:
- users[name] = {"sent": sent, "received": received}
- elif command == "Message":
- sender = tokens[1]
- receiver = tokens[2]
- if sender in users and receiver in users:
- users[sender]["sent"] += 1
- if users[sender]["sent"] + users[sender]["received"] == max_capacity:
- users.pop(sender)
- print(f"{sender} reached the capacity!")
- users[receiver]["received"] += 1
- if users[receiver]["received"] + users[receiver]["sent"] == max_capacity:
- users.pop(receiver)
- print(f"{receiver} reached the capacity!")
- elif command == "Empty":
- name = tokens[1]
- if name == "All":
- users = {}
- elif name in users:
- users.pop(name)
- line = input()
- print(f"Users count: {len(users)}")
- for user, data in sorted(users.items(), key=lambda kvp: (-kvp[1]["received"], kvp[0])):
- total = data["received"] + data["sent"]
- print(f"{user} - {total}")
Advertisement
Add Comment
Please, Sign In to add comment