关注
#第二题 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]+"},"
查看原帖
点赞 评论
相关推荐
10-11 00:13
南华大学 嵌入式软件开发 点赞 评论 收藏
分享
10-20 20:16
中国农业大学 算法工程师 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 牛客树洞,我想对你说 #
12780次浏览 110人参与
# 大学最后一个寒假,我想…… #
54575次浏览 599人参与
# 快手技术岗信息交流阵地 #
5737次浏览 47人参与
# 怎么给家人解释你的工作? #
13994次浏览 83人参与
# 如何KTV领导 #
73425次浏览 505人参与
# 你的mentor是什么样的人? #
18038次浏览 117人参与
# 牛客周边新品开箱 #
11078次浏览 91人参与
# 机械人集合!你是什么工程师? #
20589次浏览 91人参与
# 硬件人的春招flag #
52355次浏览 435人参与
# 应届生被毁约被毁意向了怎么办 #
47048次浏览 280人参与
# 求职中的尴尬瞬间 #
5604次浏览 49人参与
# 三一集团提前批进度交流 #
39028次浏览 225人参与
# 机械人避雷的岗位/公司 #
29068次浏览 245人参与
# 牛友的志愿填报指南 #
35745次浏览 188人参与
# 大疆工作体验 #
19432次浏览 85人参与
# 国企还是互联网,你怎么选? #
171666次浏览 1302人参与
# 得物app工作体验 #
29239次浏览 68人参与
# 帮我看看,领导说这话什么意思? #
23942次浏览 105人参与
# 今年形式下双非本找得到工作吗 #
238842次浏览 1435人参与
# 校招泡的最久的公司是哪家? #
14608次浏览 90人参与
# 产品面经 #
224186次浏览 2060人参与
查看5道真题和解析