阿里say no~
阿里笔试0907,跪到膝盖疼~
这叫算法编程吗?苦笑~
import sys def main(): database = sys.stdin.readline().strip() query = sys.stdin.readline().strip() dict = {} for obj in database.split(';'): name = obj.split('_')[0] value = obj.split('_')[1].split('|') for v in value: if v in dict: dict[v].append(name) else: dict[v] = [name] res = {} for ind in dict: if ind in query: idx = query.index(ind) if (idx not in res) or len(ind) > len(res[idx]): res[idx] = ind # print(res) str = [] start = 0 for key in sorted(res.keys()): str.extend([query[start:key], ' ', res[key], '/']) start = key + len(res[key]) # print(str) for v in sorted(dict[res[key]]): str.extend([v, ',']) str[-1] = ' ' # if start == len(query): # str.pop() # else: str.append(query[start:]) sys.stdout.write(''.join(str)) main()#阿里巴巴#