关注
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_周杰伦|孙俪
# 请播放周杰伦的七里香给周杰伦周杰孙俪听周杰王力宏
查看原帖
点赞 评论
相关推荐
查看16道真题和解析
点赞 评论 收藏
转发
牛客热帖
- 1... 计算机专业可以去哪些央国企(总论篇)?5.1W
- 2... 网易互娱40min(感觉是G了)5242
- 3... 大二终于拿下大厂(附 timeline)4853
- 4... 华黑子的暑期实习总结4749
- 5... 只能只认倒霉吗?4420
- 6... OPPO OC,欧欧欧欧欧欧4224
- 7... 小公司要求真高4195
- 8... 六月初被无良央企毁三方 现在很迷茫4151
- 9... 6月了,好公司都开始校招了3962
- 10... 一个大学毕业生在河边哭,他哭的如此伤心,连河神都动容了。河神拿着一份月薪两万但996的工作offer,和一份月薪2000但朝九暮五、双休的工作offer,问:“这两个哪个是你的?”毕业生哭着说:“都不是我的,自从我大学毕业之后就没找到工作。”河神说:“你很诚实,两个都给你吧。“于是毕业生得到了一份月薪2000,还996的工作。河神说:“记住,这是你的福报。3814
正在热议
# 和牛牛一起刷题打卡 #
20298次浏览 1689人参与
# 0offer是寒冬太冷还是我太菜 #
456913次浏览 5147人参与
# 不去互联网可以去金融科技 #
25102次浏览 328人参与
# 牛客帮帮团来啦!有问必答 #
1164143次浏览 17277人参与
# 学历对求职的影响 #
162314次浏览 1821人参与
# 市场营销面经 #
8400次浏览 171人参与
# OPPO开奖 #
21876次浏览 322人参与
# 小厂实习有必要去吗 #
4007次浏览 47人参与
# 机械只有转码才有出路吗? #
2827次浏览 69人参与
# 机械人与华为的爱恨情仇 #
10650次浏览 82人参与
# 听劝,我这个简历该怎么改? #
63660次浏览 627人参与
# 通信和硬件还有转码的必要吗 #
11498次浏览 101人参与
# 大厂无回复,继续等待还是奔赴小厂 #
6214次浏览 41人参与
# 简历无回复,你会继续海投还是优化再投? #
25187次浏览 355人参与
# 参加过提前批的机械人,你们还参加秋招么 #
14712次浏览 349人参与
# 国企是理工四大天坑的最好选择吗 #
2366次浏览 34人参与
# 晒一晒我的offer #
3841209次浏览 58736人参与
# 实习与准备秋招该如何平衡 #
204483次浏览 3642人参与
# 为什么那么多公司毁约 #
62695次浏览 575人参与
# 产品人求职现状 #
57956次浏览 834人参与
# 产运销实习日记 #
1401次浏览 50人参与
# 为什么国企只招应届生 #
58934次浏览 436人参与