关注
#第二题 ac
trans = {"a":10,"b":11,"c":12,"d":13,"e":14,"f":15}
result = {}
seen = {}
find = 0
def get_id(string):
count = 0
for i in string:
if i in trans:
i = trans[i]
else:
i = int(i)
count = count * 16 + i
return count
def start1(start,key):
global find,seen
if key in result:
# print start,"key_list:",result[key]["after"]
if start in result[key]["after"]:
find = 1
else:
for item in result[key]["after"]:
# print "in",item
if not seen[item]:
seen[item] = True
start1(start,item)
def clear():
global seen
for key,value in seen.items():
seen[key] = False
# count = 0
while True:
flag = 1
data = raw_input()
if "}," not in data:
flag = 0
id1 = data.split(",")[0].replace("{","").strip()
id2 = data.split(",")[1].replace("}","").replace(",","").strip()
if id1 in result:
result[id1]["after"].append(id2)
else:
result[id1] = {"index":get_id(id1.replace("0x","")),"after":[id2]}
if id2 not in result:
result[id2] = {"index":get_id(id2.replace("0x","")),"after":[]}
if id1 not in seen:
seen[id1] = False
if id2 not in seen:
seen[id2] = False
if flag == 0:
break
# print count
result_list = []
for key,value in result.items():
# print key
clear()
seen[key] = True
start1(key,key)
# print "find",find
if find == 0:
result_list.append([value["index"],key,"false"])
else:
result_list.append([value["index"],key,"true"])
find = 0
this_count = 0
for item in sorted(result_list,key = lambda x:x[0]):
this_count += 1
# print this_count
if (this_count == len(result_list)):
print "{"+item[1]+", "+item[2]+"}"
else:
print "{"+item[1]+", "+item[2]+"},"
查看原帖
点赞 评论
相关推荐
07-11 12:00
北京航空航天大学 Web前端 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你被哪些公司秒挂过? #
7114次浏览 105人参与
# 26届的你们有几段实习? #
2122次浏览 52人参与
# 如何提高实习转正率? #
4489次浏览 85人参与
# 第一份工作应该只看薪资吗 #
152679次浏览 1530人参与
# 大厂面试初体验 #
11610次浏览 82人参与
# 你想留在一线还是回老家? #
48835次浏览 503人参与
# 你认为哪些项目算烂大街? #
2852次浏览 77人参与
# 选完offer后,你后悔学本专业吗 #
47763次浏览 239人参与
# 你后悔自己读研吗? #
3838次浏览 109人参与
# 拼多多工作体验 #
29378次浏览 201人参与
# 你以为的实习VS真实的实习 #
3213次浏览 57人参与
# 离家近房租贵VS离家远但房租低,怎么选 #
9476次浏览 119人参与
# 月薪多少能在一线城市生存 #
4761次浏览 103人参与
# 最难的技术面是哪家公司? #
2290次浏览 35人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
113851次浏览 792人参与
# leader认为你工作不认真怎么办 #
31834次浏览 150人参与
# 如果公司降薪,你会跳槽吗? #
79965次浏览 588人参与
# 如果可以,你希望哪个公司来捞你 #
103555次浏览 496人参与
# 妈妈治愈了你哪些脆皮时刻 #
29306次浏览 321人参与
# 如果公司给你放一天假,你会怎么度过? #
17542次浏览 129人参与