关注
#第二题 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]+"},"
查看原帖
点赞 评论
相关推荐
2025-12-19 18:50
门头沟学院 golang 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 春招什么时候投? #
5133次浏览 76人参与
# 春节提前走,你用什么理由请假? #
4985次浏览 108人参与
# 春节前,你还在投简历吗? #
7231次浏览 95人参与
# 实习到现在,你最困惑的一个问题 #
1932次浏览 56人参与
# 牛客AI体验站 #
13369次浏览 253人参与
# 牛友的春节生活 #
1684次浏览 57人参与
# 备战春招/暑实,现在应该做什么? #
1677次浏览 53人参与
# 从夯到拉,锐评职场mentor #
1573次浏览 31人参与
# 聊聊Agent开发 #
14516次浏览 363人参与
# 距离春招还有一个月,你现在是什么开局? #
2951次浏览 53人参与
# 推荐一个值得做的AI项目 #
3961次浏览 125人参与
# 暑期实习什么时候投? #
3595次浏览 84人参与
# 实习想申请秋招offer,能不能argue薪资 #
218596次浏览 1171人参与
# 腾讯工作体验 #
566943次浏览 3701人参与
# 哪些瞬间让你真切感受到了工作的乐趣 #
24448次浏览 105人参与
# 通信硬件2024笔试面试经验 #
269170次浏览 2053人参与
# 实习必须要去大厂吗? #
188511次浏览 1767人参与
# 正在春招的你,也参与了去年秋招吗? #
349929次浏览 2590人参与
# 双非本科的出路是什么? #
208713次浏览 1566人参与
# 最难的技术面是哪家公司? #
65412次浏览 971人参与
查看1道真题和解析
格力公司福利 345人发布