Rotate Corners – Anticlockwise Direction: The program must accept a character matrix of size N*N as the input. For each layer in the matrix, the program must rotate the characters in the four corners by 1 position in anticlockwise direction. Finally, the program must print the modified matrix as the output.
Boundary Condition(s):
3 <= N <= 50
Input Format:
The first line contains N.
The next N lines, each contains N characters separated by a space.
Output Format:
The first N lines, each contains N characters separated by a space.
Example Input/Output 1:
Input:
4
i k m e
b h t o
u r d k
w d i v
Output:
e k m v
b t d o
u h r k
i d i w
Explanation:
There are 2 layers in the given matrix.
After rotating the values in the four corners of the 1st layer, the matrix becomes
e k m v
b h t o
ur d k
i d i w
After rotating the values in the four corners of the 2nd layer, the matrix becomes
e k m v
b t d o
u h r k
i d i w
So the above matrix is printed as the output.
Example Input/Output 2:
Input:
5
x R p Y v
A h W t r
z W l v e
g v R I p
p q C l Z
Output:
v R p Y Z
A t W I r
z W l v e
g h R v p
x q C l p
a=int(input())
l=[]
for i in range(a):
l.append(list(map(str,input().split())))
b=a-1
for i in range(a//2):
k=[l[i][i],l[i][b-i],l[b-i][i],l[b-i][b-i]]
l[i][b-i]=k[3]
l[i][i]=k[1]
l[b-i][i]=k[0]
l[b-i][b-i]=k[2]
for i in l:
print(*i,sep=" ")