分班
分班
标题:分班 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
幼儿园两个班的小朋友在排队时混在了一起,每位小朋友都知道自己是否与前面一位小朋友是否同班,请你帮忙把同班的小朋友找出来。
小朋友的编号为整数,与前一位小朋友同班用Y表示,不同班用N表示。
def judge(child_num): if child_num <= 0&nbs***bsp;child_num > 999: return False return True while True: try: children = input().split() if len(children) == 0: print("ERROR") continue class_1, class_2 = list(),list() flag = True for child in children: if child == children[0]: child_num = int(child.split("/")[0]) if not judge(child_num): print("ERROR") break class_1.append(child_num) else: chlid_num,chlid_sign = int(child.split("/")[0]),child.split("/")[1] if not judge(chlid_num): print("ERROR") break if chlid_sign == "N": flag = not flag if flag: class_1.append(chlid_num) else: class_2.append(chlid_num) class_1.sort() class_2.sort() if class_1 == []&nbs***bsp;class_2 == []: class_list =class_1+class_2 print(" ".join([str(i) for i in class_list])) continue if class_1[0] <= class_2[0]: print(" ".join([str(x) for x in class_1])) print(" ".join([str(x) for x in class_2])) else: print(" ".join([str(x)for x in class_2])) print(" ".join([str(x) for x in class_1])) except: break