PROBLEM STATEMENT
Points: 30
You are given a square matrix of size n. Rows are indexed 1 to n from top to bottom and columns are indexed 1 to n form left to right. Matrix consists of only '*' and '.'. You need to check whether matrix is symmetric or not. if it is, check it is symmetric about vertical axis or horizontal axis or both.
A matrix is said to be symmetric about horizontal axis if row is identical to row, is identical to row and so on...
A matrix is said to be symmetric about vertical axis if column is identical to nth column, identical to and so on for all columns.
INPUT :
First line contains t,the number of test cases. First line of each test case contains n the size of matrix. Each of next n lines contain n characters.
OUTPUT:
Output t lines, answer for each test case. Print "HORIZONTAL" if symmetric about horizontal axis. Print "VERTICAL" if symmetric about vertical axis. Print "BOTH" if symmetric about both axes. print "NO" if it is not symmetric.
Constraints :
Solution in python:
list2 = []
t = int(input())
for i in range(t) :
list1 = []
count = 0
count2 = 0
n = int(input())
for j in range(0,n) :
list1.append(input().split([0])
for k in range(0,n) :
if list1[0+k] != list1[n-1-k] :
count = 0
break
else :
count=1
for j in range(n) :
for k in range(n) :
if list1[0+k][0+j] != list1[0+k][n-1-j] :
count2 = 0
break
else :
count2 = 1
if count==0 and count2==0 :
list2.append('NO')
elif count==0 and count2 :
list2.append('VERTICAL')
elif count and count2 == 0 :
list2.append('HORIZONTAL')
else :
list2.append('BOTH')
for i in list2 :
print(i)
No comments:
Post a Comment