forked from anubhab91/CodeForces-5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture.py
More file actions
37 lines (24 loc) · 941 Bytes
/
Lecture.py
File metadata and controls
37 lines (24 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
__author__ = 'Devesh Bajpai'
'''
https://codeforces.com/problemset/problem/499/B
Solution: Keep a mapping of prof's words to student's words in a dictionary. Now run through the sentence and check
if the mapped word (student's word) has a lesser length than the prof's word. If so, use it in the notes, else use profs.
This helps to give preference to prof's words when lengths are same.
'''
def solve(dict, sentence):
notesSentence = []
for word in sentence:
mappedWord = dict[word]
if len(mappedWord) < len(word):
notesSentence.append(mappedWord)
else:
notesSentence.append(word)
return ' '.join(notesSentence)
if __name__ == "__main__":
n,m = map(int, raw_input().split(" "))
dict = {}
for _m in xrange(0,m):
words = raw_input().split(" ")
dict[words[0]] = words[1]
sentence = raw_input().split(" ")
print solve(dict, sentence)