关注
#第二题 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:21
中南大学 Java 点赞 评论 收藏
分享
点赞 评论 收藏
分享
要发财的coder很...:快手内推是诈骗,骗钱你改简历呢

点赞 评论 收藏
分享
07-02 16:43
门头沟学院 硬件开发 码农索隆:面试官挺好的,至少告诉你现在市面上需要什么样的人,不必灰心,根据面试官说的,好好提升自己,offer会有的

点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 大家每天通勤多久? #
45901次浏览 346人参与
# 银行笔面经互助 #
134284次浏览 1168人参与
# 现代汽车前瞻技术研发急速编程挑战赛 #
33603次浏览 259人参与
# 上班到公司第一件事做什么? #
58617次浏览 500人参与
# 设计人如何选offer #
119282次浏览 741人参与
# CVTE求职进展汇总 #
16408次浏览 292人参与
# 上班苦还是上学苦呢? #
229685次浏览 1357人参与
# 非技术投递记录 #
604511次浏览 6402人参与
# 90后北漂现状 #
24903次浏览 201人参与
# 百度工作体验 #
227011次浏览 1996人参与
# 机械人与华为的爱恨情仇 #
117884次浏览 951人参与
# 金融财会交流会 #
110588次浏览 380人参与
# 工作中,努力重要还是选择重要? #
137234次浏览 1683人参与
# 发工资后,你做的第一件事是什么 #
68757次浏览 232人参与
# 机械人,你的秋招第一份简历被谁挂了 #
141722次浏览 1982人参与
# Offer比较,你最看重什么? #
187001次浏览 1288人参与
# 工作中哪个瞬间让你想离职 #
26462次浏览 179人参与
# 你觉得实习能学到东西吗 #
40950次浏览 780人参与
# 秋招什么时候开投比较合适? #
29109次浏览 353人参与
# 联想求职进展汇总 #
271070次浏览 2053人参与
# 机械人集合!你是什么工程师? #
16403次浏览 89人参与