Files
kattis/securedoors.py
2023-07-18 13:57:24 +00:00

26 lines
573 B
Python

state = {}
def detect_anomaly(name: str, action: str) -> str:
global state
try:
if state[name] == action:
return " (ANOMALY)"
except KeyError:
if action == "exit":
return " (ANOMALY)"
return ""
def print_log(name: str, action: str) -> None:
paction = "entered" if action == "entry" else "exited"
print(f"{name} {paction}{detect_anomaly(name, action)}")
n = int(input())
for _ in range(n):
action, name = input().split()
print_log(name, action)
state[name] = action