Sort by

recency

|

580 Discussions

|

  • + 0 comments

    import math import os import random import re import sys

    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 = [char for char in input()] matrix.append(matrix_item) zipped_list = list(zip(*matrix)) for i in range(m): zipped_list[i] = "".join(zipped_list[i]) decodedMsg = "".join(zipped_list)

    matches = re.sub(r'(?<=\w)[^\w]+(?=\w)',' ', decodedMsg) print(matches)

  • + 0 comments
    #!/bin/python3
    
    import re
    
    # Read the matrix dimensions
    first_multiple_input = input().rstrip().split()
    n = int(first_multiple_input[0])  # Number of rows
    m = int(first_multiple_input[1])  # Number of columns
    
    # Read the matrix
    matrix = []
    for _ in range(n):
        matrix_item = input()
        matrix.append(matrix_item)
    
    # Transpose the matrix to read columns as rows
    decoded_script = ''.join([matrix[i][j] for j in range(m) for i in range(n)])
    
    # Replace non-alphanumeric characters between alphanumeric characters with a single space
    cleaned_script = re.sub(r'(?<=\w)[^\w]+(?=\w)', ' ', decoded_script)
    
    # Print the cleaned decoded script
    print(cleaned_script)
    
  • + 0 comments

    Very nice. Already checked for trailing spaces. No idea what happened.

    Your Output (stdout) This is Matrix# %!

    Expected Output This is Matrix# %!

  • + 0 comments

    Wow its increadible how much easier this can be done. Thank you for sharing people. I have written solution myself, it gives the same answers in the tests but for some reason it says its not correct in here. Maybe you can help to see why

    Edit: I found that i do if r"name"== r"main" and that was the problem!

    import re
    
    def main():
        first_multiple_input = input().rstrip().split()
        n = int(first_multiple_input[0])
        matrix = []
        for _ in range(n):
            matrix_item = input()
            matrix.append(matrix_item)
        my_string = matrix_to_string(matrix)
        print(decode(my_string))
    
    def matrix_to_string(matrix):
        transposed_matrix = []
        for new_row in zip(*matrix):
            for s in new_row:
                transposed_matrix.append(s)
        return "".join(transposed_matrix)
    
    def decode(my_string):
        code, part_string = find_begining(my_string)
        my_string = my_string.replace(part_string, "")
        decoded = code
        while code:
            try:
                code, part_string = find_begining(my_string)
            except AttributeError:
                break
            my_string = my_string.replace(part_string, "")
            decoded = f"{decoded} {code}"
        return decoded + my_string
    
    def find_begining(string):
        my_match = re.match(r"(^[\W]*([\w]+))", string)
        return my_match.group(2), my_match.group(1)
    
    if __name__ == "__main__":
        main()
    
  • + 0 comments

    Easy solution

    tekst = ""
    for i in range(m):
        for j in range(n):
            tekst += matrix[j][i]
    print(re.sub(r'(?<=[a-zA-Z0-9])[^a-zA-Z0-9]+(?=[a-zA-Z0-9])', ' ', tekst))