关注
#第二题 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]+"},"
查看原帖
点赞 评论
相关推荐
04-17 09:20
河南科技大学 Java 点赞 评论 收藏
分享
03-27 13:42
北京交通大学 算法工程师 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 哪些AI项目值得做? #
16102次浏览 429人参与
# 秋招笔试记录 #
397639次浏览 2194人参与
# 华泰星战营,提前锁定校招offer #
11677次浏览 354人参与
# 实习时最怕听到的一句话 #
14708次浏览 137人参与
# 90后北漂现状 #
38731次浏览 225人参与
# 找不到大厂实习可以去小厂吗? #
12912次浏览 112人参与
# 机械人,说说你的烦心事 #
143963次浏览 1150人参与
# 应届生初入职场,求建议 #
332531次浏览 2916人参与
# 简历上如何体现你的“AI”能力? #
7349次浏览 172人参与
# 你简历上最心虚的一句话 #
14879次浏览 156人参与
# 没有面试的日子里,你在做什么 #
8643次浏览 230人参与
# 携程笔试 #
162398次浏览 903人参与
# 如果有时光机,你最想去到哪个年纪? #
77103次浏览 858人参与
# 你总挂在第__面? #
5466次浏览 57人参与
# ai智能作图 #
682515次浏览 5727人参与
# 汉得笔试 #
3904次浏览 23人参与
# 24届秋招同行攻略分享 #
1478902次浏览 14432人参与
# 你知道最慷慨和最抠的公司分别是 #
7246次浏览 59人参与
# 绿盟笔试 #
3429次浏览 24人参与
# 大厂无回复,继续等待还是奔赴小厂 #
356862次浏览 2024人参与
# 机械人还在等华为开奖吗? #
333962次浏览 1628人参与
