Untitled

mail@pastecode.io avatar
unknown
python
a month ago
823 B
1
Indexable
Never
def SymmetricMatrix(strArr):
    matrix = [[]]
    # build matrix from parsed string
    for entry in strArr:
        if entry != '<>':
            matrix[len(matrix) - 1].append(entry)
        else:
            matrix.append([])
    # convert strings to numbers
    for row in matrix:
        for i in range(len(row)):
            row[i] = int(row[i])

    # check to see if matrix is square
    if len(matrix[0]) != len(matrix):
        return 'not possible'

    # check each number's transposed place within matrix for equality
    for i in range(len(matrix)):
        for j in range(i + 1, len(matrix)):
            if matrix[i][j] != matrix[j][i]:
                return 'not symmetric'
    return 'symmetric'

# Example usage
import sys
print SymmetricMatrix(sys.stdin.readline().split())
Leave a Comment