关注
#第二题 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]+"},"
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 2025年终总结 #
150690次浏览 2563人参与
# 你面试体验感最差/最好的公司 #
3937次浏览 72人参与
# 重来一次,你会对开始求职的自己说 #
3331次浏览 78人参与
# 一人说一个提前实习的好处 #
4022次浏览 81人参与
# 实习没事做是福还是祸? #
8941次浏览 139人参与
# 团建是“福利”还是是 “渡劫” #
4353次浏览 116人参与
# 秋招落幕,你是He or Be #
3881次浏览 85人参与
# 今年你最想重开的一场面试是? #
1614次浏览 27人参与
# 你小心翼翼的闯过多大的祸? #
7466次浏览 110人参与
# 工作中听到最受打击的一句话 #
2948次浏览 64人参与
# 大厂VS公务员你怎么选 #
71759次浏览 662人参与
# 实习简历求拷打 #
31044次浏览 304人参与
# 应届生进小公司有什么影响吗 #
109264次浏览 1118人参与
# 如何排解工作中的焦虑 #
244514次浏览 2250人参与
# 比亚迪工作体验 #
70681次浏览 257人参与
# 秋招结束之后的日子 #
113957次浏览 1044人参与
# 投格力的你,拿到offer了吗? #
156189次浏览 835人参与
# 找不到实习会影响秋招吗 #
1401547次浏览 13653人参与
# 扒一扒那些奇葩实习经历 #
140626次浏览 1151人参与
# 互联网公司爆料 #
158658次浏览 724人参与
腾讯成长空间 5933人发布