Find A Sub-Word

Sort by

recency

|

162 Discussions

|

  • + 0 comments

    TypeScript and Javascript come with more boilerplate code, but they are not complete. This confuses the entire problem because sometimes hackerrank labels finished code or locks it.

    Additionally, "input" is ambiguous. Sometimes it means "read from stdin" and sometimes it means read from file, unless I am missing something.

  • + 0 comments
    import re
    n=int(input())
    text=" ".join(input() for _ in range(n))
    b=int(input())
    for _ in range(b):
        i=input()
        matches=re.findall(fr"(?<=\w){re.escape(i)}(?=\w)",text)
        print(len(matches))
    
  • + 0 comments
    import re
    
    n=int(input())
    lines="\n".join([input() for _ in range(n)])
    
    q=int(input())
    sub=[input() for _ in range(q)]
    
    for i in sub:
        pattern=re.compile(r"\B"+i+r"\B")
        matches=re.findall(pattern,lines)
        print(len(matches))
    
  • + 0 comments

    Pthon code:

    import re
    
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    n = int(input())
    if not (1 <= n <= 100):
        raise ValueError("Number of lines must be between 1 and 100")
    lines = []
    for i in range(n):
        lines.append(input())
    q = int(input())
    if not (1 <= q <= 100):
        raise ValueError("Queries must be between 1 and 10")
    queries = []
    for i in range(q):
        queries.append(input())
    
    # print(n)
    # print(lines)
    # print(q)
    # print(queries)
    
    patterns = []
    for query in queries:
        pattern = '[A-Za-z0-9_]'+query+'[A-Za-z0-9_]'
        patterns.append(pattern)
    
    sum = 0
    for patten in patterns:
        for line in lines:
            x = re.findall(patten,line)
            sum = sum + len(x)
        print(sum)
        sum = 0
    
  • + 0 comments

    Python3:

    import re
    import sys
    
    data = sys.stdin.read()
    
    pattern=r'\n[0-9]*\n([A-z\n]*)'
    
    matches = re.findall(pattern, data)
    
    for word in matches[0].split("\n"):
        myregex= r"([A-z]" + re.escape(word) + r"[A-z])"
        print(len(re.findall(myregex, data, re.IGNORECASE)))