-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththesaurus.py
39 lines (33 loc) · 986 Bytes
/
thesaurus.py
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
38
39
# thesaurus
# Author: Debbie Macrohon
# Description:
def findMin(newPhraseFull,c):
newPhraseArray = newPhraseFull.split(" ")
if newPhraseArray[c] in thesaurus and c >=0:
newPhraseArray[c] = thesaurus[newPhraseArray[c]]
newPhraseAfter = ''.join(newPhraseArray)
print(newPhraseAfter)
print(c)
if len(newPhraseAfter)<len(newPhraseFull):
return len(newPhraseAfter)
else:
return len(newPhraseFull)
return min(findMin(newPhraseFull,c-1),findMin(newPhraseAfter,c-1))
vars = [int(i) for i in input().split(" ")]
n = vars[0]
m = vars[1]
thesaurus = {}
phrase = input()
for i in range(m):
thes = input().split(" ")
key = thes[0]
val = thes[1]
thesaurus[key] = val
phrasewords = phrase.split()
print(thesaurus)
leastCount = len(''.join(phrasewords))
for i in phrasewords:
res = findMin(phrase,len(phrasewords)-1)
if leastCount>res:
leastCount = res
print(res,leastCount)