wellformed.py (1425B)
1 #!/usr/bin/python 2 3 import sys 4 5 status = {} 6 no = 0 7 onstage = 0 8 maxonstage = 0 9 reached = 0 10 11 while True: 12 l = sys.stdin.readline() 13 no += 1 14 if not l: 15 break 16 f = l.strip().split(' ') 17 if len(f) < 2: 18 continue 19 p = f[0] 20 fw = f[2] 21 if p not in status.keys(): 22 status[p] = "out" 23 if fw == "/join": 24 if status[p] != "out": 25 print("line %d: %s joins but is already on stage" % (no, p)) 26 status[p] = "in" 27 onstage += 1 28 if onstage > maxonstage: 29 maxonstage = onstage 30 reached = no 31 elif fw == "/part": 32 if status[p] != "in": 33 print("line %d: %s leaves but is already out of stage" % (no, p)) 34 status[p] = "out" 35 onstage -= 1 36 #elif fw == "/nick": 37 # fw2 = f[3] 38 # if fw2 not in status.keys(): 39 # status[fw2] = "out" 40 # if status[fw2] != "out": 41 # print("line %d: %s name clash" % (no, fw2)) 42 # if status[p] != "in": 43 # print("line %d: %s leaves but is already out of stage" % (no, p)) 44 # status[p] = "out" 45 # status[fw2] = "in" 46 elif p == "ER" and f[3].startswith("Rideau"): 47 for x in status.keys(): 48 if x == "ER": 49 continue 50 if status[x] != "out": 51 print("line %d: %s still on stage at act end" % (no, x)) 52 elif p != "ER" and fw != "/nick": 53 if status[p] != "in": 54 print("line %d: %s speaks but is out of stage" % (no, p)) 55 status[p] = "in" 56 57 58 print("Max on stage: %d at line %d" % (maxonstage, reached))