关注
#第二题 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-14 19:18
门头沟学院 化工工程师 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 职场捅娄子大赛 #
298975次浏览 2986人参与
# 上班苦还是上学苦呢? #
220185次浏览 1301人参与
# 华泰证券Fintech星战营 #
164673次浏览 186人参与
# 写给毕业5年后的自己 #
1115次浏览 23人参与
# 如何缓解求职过程中的焦虑? #
3422次浏览 60人参与
# 华为求职进展汇总 #
4625757次浏览 28177人参与
# 好好告别我的学生时代 #
15957次浏览 338人参与
# 晒一下我的毕业照 #
23298次浏览 199人参与
# 简历无回复,你会继续海投还是优化再投? #
67666次浏览 693人参与
# 互联网行业现在还值得去吗 #
16581次浏览 54人参与
# 2025,我想...... #
47902次浏览 459人参与
# 节后第一天上班,我的精神状态 #
8968次浏览 80人参与
# 运营来爆料 #
42857次浏览 320人参与
# 记录实习开销 #
12639次浏览 96人参与
# 00后45度躺现状 #
92585次浏览 478人参与
# 考公VS就业,你怎么选? #
57915次浏览 388人参与
# 来聊聊机械薪资天花板是哪家 #
121769次浏览 736人参与
# 机械人,签完三方你在忙什么? #
48390次浏览 211人参与
# 如何KTV领导 #
55093次浏览 413人参与
# 租房前辈的忠告 #
167380次浏览 6343人参与
# 嵌入式岗知多少 #
38985次浏览 425人参与