Sort by

recency

|

586 Discussions

|

  • + 0 comments
    #!/bin/python3
    
    import re
    
    first_multiple_input = input().rstrip().split()
    
    N = int(first_multiple_input[0])
    
    M = int(first_multiple_input[1])
    
    matrix = []
    
    for _ in range(N):
        matrix_item = input()
        matrix.append(matrix_item)
    
    decoded = ""
    
    for m in range(M):
        for n in range(N):
            decoded +=matrix[n][m]
    
    clean = re.sub(r'(?<=[A-Za-z0-9])[^A-Za-z0-9]+(?=[A-Za-z0-9])', ' ', decoded)
    
    print(clean)
    
  • + 0 comments

    here is my solution icomplie in python 3

    !/bin/python3

    import re

    first_multiple_input = input().rstrip().split()

    n = int(first_multiple_input[0]) m = int(first_multiple_input[1])

    matrix = []

    for _ in range(n): matrix_item = input() matrix.append(matrix_item.ljust(m))

    string = ''.join(matrix[row][col] for col in range(m) for row in range(n))

    output = re.sub(r'(?<=\w)[!@#$&% ]+(?=\w)', ' ', string)

    print(output)

  • + 0 comments

    import sys import re p = re.compile(r'(?<=\w)([\$#\%\s]+)(?=\w)') dem = sys.stdin.readline().split(); r = int(dem[0]) c = int(dem[1]) rows = [l for l in sys.stdin] text = ""; for i in range(c): for j in range(r): text = text+rows[j][i] print(p.sub(' ',text))

  • + 0 comments

    import sys import re p = re.compile(r'(?<=\w)([\$#\%\s]+)(?=\w)') dem = sys.stdin.readline().split(); r = int(dem[0]) c = int(dem[1]) rows = [l for l in sys.stdin] text = ""; for i in range(c): for j in range(r): text = text+rows[j][i] print(p.sub(' ',text))

  • + 0 comments

    Explanation of Changes and Why This Works:

    1) Integration with Provided Skeleton: The key here was to take the already provided HackerRank code skeleton (which handles the input) and add the decoding logic after it. The provided skeleton reads the n, m, and the matrix elements.

    2) Decoding Logic (Unchanged and Correct): The core decoding logic (building the decoded_script string and the regular expression) remains exactly the same as in my previous fully working response. This is the most important part, and it's already been thoroughly vetted and explained. We're simply inserting it into the HackerRank structure.

    3) No Changes to Input Reading: The first_multiple_input, n, m, matrix variable assignments, and the for loop to read the matrix are all left untouched. This is exactly what the HackerRank environment expects.

    Output: The print() statement is placed after the provided input-reading code and after my added decoding logic. This is the correct place to generate the output.