Last active
February 10, 2022 17:57
-
-
Save Crisher70/35bb0d850ed26cd1c61a029287187088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
lineMorse ="" | |
dictionary=[] | |
alphabet = { | |
"a":".-", "b":"-...", "c":"-.-.", "d":"-..", "e":".", "f":"..-.", "g":"--.", "h":"....", | |
"i":"..", "j":".---", "k":"-.-", "l":".-..", "m":"--", "n":"-.", "o":"---", "p":".--.", | |
"q":"--.-", "r":".-.", "s":"...", "t":"-", "u":"..-", "v":"...-", "w":".--", "x":"-..-", | |
"y":"-.--", "z":"--.." | |
} | |
def convertWordToMorse(word): | |
wordMorse="" | |
for letter in word: | |
wordMorse += alphabet[letter.lower()] | |
return wordMorse | |
def getLineMorse(): | |
while True: | |
morse = input() | |
if len(morse) > 0 and len(morse) < 10000: | |
return morse | |
def getDictionary(): | |
while True: | |
num = int(input()) | |
if num < 0 or num > 10000: | |
return | |
dictionary = [] | |
cont = 0 | |
while cont < num: | |
word = str(input()) | |
if len(word) > 0 and len(word) < 20: | |
if word not in dictionary: | |
dictionary.append(word) | |
cont+=1 | |
return dictionary | |
def convertListToMorse(dictionary): | |
list = [] | |
for word in dictionary: | |
list.append(convertWordToMorse(word)) | |
return list | |
def numberOfMatches(lineMorse,dictionary): | |
cont=0 | |
for word in dictionary: | |
if lineMorse.find(word) == 0: | |
cont+=1 | |
return cont | |
#EJECUCION | |
lineMorse = getLineMorse() | |
dictionary = getDictionary() | |
dictionaryMorse = convertListToMorse(dictionary) | |
matches = numberOfMatches(lineMorse, dictionaryMorse) | |
print(matches) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment