关注
import re
def process_main3():
row1 = raw_input()
datas = {}
entity_str_list = row1.split(";")
for entity_str in entity_str_list:
entity_name, entity_values = entity_str.split("_")
entity_value_list = entity_values.split("|")
for entity_value in entity_value_list:
if datas.has_key(entity_value):
datas[entity_value].append(entity_name)
else:
datas[entity_value] = [entity_name]
entity_list = sorted(datas.keys(), reverse=True)
row2 = raw_input()
words = row2
result = {}
tmp_words = words
temp_entity = ""
count = 1
for entity_value in entity_list:
if entity_value in tmp_words:
location = re.search(entity_value, words)
local_tuple = location.span()
if temp_entity == "":
temp_entity = entity_value
temp_tuple = local_tuple
else:
result[temp_entity] = datas[temp_entity]
tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
count += 1
temp_entity = entity_value
temp_tuple = local_tuple
else:
if temp_entity != "":
result[temp_entity] = datas[temp_entity]
tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
count += 1
temp_entity = ""
if temp_entity != "":
result[temp_entity] = datas[temp_entity]
tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
final_list = sorted(result.keys(), reverse=True)
for index in xrange(len(final_list)):
st = ",".join(result[final_list[index]])
new_str = " " + final_list[index] + "/" + st + " "
tmp_words = tmp_words.replace("|&{}&|".format(index + 1), new_str)
print " ".join(tmp_words.split())
if __name__ == '__main__':
# main_process()
process_main3()
# singer_周杰|周杰伦|刘德华|王力宏;song_冰雨|北京欢迎你|七里香;actor_周杰伦|孙俪
# 请播放周杰伦的七里香给周杰伦周杰孙俪听周杰王力宏
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 在大厂上班是一种什么样的体验 #
3057次浏览 42人参与
# 找工作的破防时刻 #
251184次浏览 1947人参与
# 程序员找工作至少要刷多少题? #
6410次浏览 106人参与
# OPPO求职进展汇总 #
770550次浏览 5395人参与
# 论秋招对个人心气的改变 #
4495次浏览 78人参与
# 程序员能干到多少岁? #
4716次浏览 72人参与
# 为了减少AI幻觉,你注入过哪些设定? #
1313次浏览 41人参与
# 刚入职的你踩过哪些坑 #
3064次浏览 67人参与
# 一张图晒一下你的AI员工 #
2170次浏览 51人参与
# 牛客AI体验站 #
2364次浏览 70人参与
# AI Coding的使用心得 #
1836次浏览 45人参与
# 我现在比当时_,你想录用我吗 #
2981次浏览 46人参与
# 关于春招/暑期实习,你想知道哪些信息? #
3092次浏览 69人参与
# 晒晒你司的新年福利 #
2984次浏览 54人参与
# 实习,不懂就问 #
163966次浏览 1459人参与
# 软开人,秋招你打算投哪些公司呢 #
180276次浏览 1385人参与
# 帆软软件工作体验 #
12621次浏览 68人参与
# 牛客租房专区 #
146515次浏览 1462人参与
# 从哪些方向判断这个offer值不值得去? #
51066次浏览 348人参与
# 简历无回复,你会继续海投还是优化再投? #
138793次浏览 875人参与