Sort by

recency

|

51 Discussions

|

  • [deleted]
    + 0 comments
    # python3
    import re
    
    f = open('dictionary.lst', 'r')
    data = f.read().lower()
    f.close()
    
    words = data.split()
    wordmap = {}
    
    for word in words:
        length = len(word)
        sub = wordmap.get(length, {})
        wordmap[length] = sub
    
        gen = ''
        for c in word:
            if c not in gen:
                gen += c
    
        key = [0] * length
        for i, c in enumerate(word):
            key[i] = gen.index(c)
        key = ' '.join([str(k) for k in key])
    
        arr = sub.get(key, [])
        sub[key] = arr
    
        arr.append(word)
    
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    cypher = ['.'] * 26
    data = input()
    enc = data.split()
    test = enc[:]
    
    def cycle():
        global test, cypher, alpha, wordmap
    
        for word in test:
            length = len(word)
    
            gen = ''
            for c in word:
                if c not in gen:
                    gen += c
    
            key = [0] * length
            pattern = ''
    
            for i, c in enumerate(word):
                key[i] = gen.index(c)
                try:
                    j = cypher.index(c)
                    pattern += alpha[j]
                except:
                    pattern += '.'
            key = ' '.join([str(k) for k in key])
    
            matches = wordmap[length][key]
            copy = []
    
            for match in matches:
                if re.fullmatch(pattern, match):
                    copy.append(match)
    
            matches = copy
    
            if len(matches) == 1:
                test.remove(word)
                match = matches[0]
                for i in range(length):
                    x = alpha.index(match[i])
                    cypher[x] = word[i]
    
    i = len(test)
    
    while True:
        cycle()
        j = len(test)
        if i == j:
            break
        i = j
    
    cypher = ''.join(cypher)
    out = [' '] * len(data)
    
    for i, c in enumerate(data):
        if c is not ' ':
            out[i] = alpha[cypher.index(c)]
    
    print(''.join(out))
    
  • [deleted]
    + 0 comments
      Solution--->(please upvote)
            (1)Read the dictionary using files.You should store all words from "dictionary.lst" in a string variable.There is only one dictionary for all the test cases.All the necessary words are provided in the dictionary to get full score 50.
        (2)So next thing to do is that input the string .
        (3)then iterate through the string using loops
             suppose
                 string is 
                 "hdsssb jidcijsd isjs sc"
                 so when we iterate through it ..we get our first word as "hdsssb"
                 now you have to find an isomorphic word to "hdsssb" from the given dictionary
                 {so the question is what are isomorphic words?
            ANS--->  Two strings are said to be isomorphic if there is a one to one mapping possible for every character of str1 to every character of str2 and all occurrences of every character in str1 map to same character in str2.
            Two strings are called isomorphic if the letters in one string can be remapped to get the second string. Remapping a letter means replacing all occurrences of it with another letter but the ordering of the letters remains unchanged. No two letters may map to the same letter, but a letter may map to itself.
     Example-1: The words "abca" and "zbxz" are isomorphic because we can map 'a' to 'z', 'b' to 'b' and 'c' to 'x'.
    Example-1: The words "bar" and "foo" are not isomorphic because we can map 'f' to 'b', 'o' to 'a' and 'o' to 'r'.
     for a more better answer look the defination on internet.}
         so when you know what are isomorphic words,you have to find an isomorph of the words given in input(i.e."hdsssb")
         supppose 
         dictionary is 
         "hello not jargon mdaaan"
         as "hdsssb" are isomorphic words so print "mdaan"
    
      you have follow all these steps for all the words provided in the input
    
            (4) The fourth point is that avoid my gramatical errors and think over the solution.Thanks for reading and please upvote.
            (5)and it is not sure that you may get full 50 points after passing all the test cases.your score may become 49.8 or 49.7..its upto you.
    
  • + 2 comments

    How do I read the dictionary file?

  • + 1 comment

    How to read dictionary with PHP language.

  • + 0 comments

    piece of cake:):) very simple