关注
#第二题 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]+"},"
查看原帖
点赞 评论
相关推荐
03-11 17:03
郑州大学 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 商战,最累的是我们 #
3119次浏览 21人参与
# 租房找室友 #
19198次浏览 117人参与
# 职场新人生存指南 #
310190次浏览 6415人参与
# 你上一次加班是什么时候? #
55546次浏览 382人参与
# 携程求职进展汇总 #
470778次浏览 3466人参与
# 深信服求职进展汇总 #
182665次浏览 1673人参与
# 学历or实习经历,哪个更重要 #
104169次浏览 723人参与
# 机械人选offer,最看重什么? #
86554次浏览 537人参与
# 秋招想进国企该如何准备 #
52898次浏览 353人参与
# 哪些公司面试官让你印象深刻? #
254058次浏览 2672人参与
# 2023届毁约公司名单 #
186791次浏览 935人参与
# 得物求职进展汇总 #
89623次浏览 791人参与
# 和牛牛一起刷题打卡 #
276584次浏览 6451人参与
# 大疆求职进展汇总 #
482571次浏览 3199人参与
# 查收我的offer竞争力报告 #
172064次浏览 1023人参与
# 如果可以,你希望哪个公司来捞你 #
74117次浏览 323人参与
# 产品面经 #
170524次浏览 1895人参与
# 通信硬件公司评价 #
122889次浏览 405人参与
# 实习要如何选择和准备? #
64377次浏览 1057人参与
# 秋招最大的收获是什么? #
26312次浏览 275人参与