Programming Assigment 4 (Deadline: May 4th Monday 23:59)

Problem

Write a C program that rotates the rings of a square letter matrix in clockwise direction a number of times.

As an example consider the 5x5 matrix:

abbba
bcdcb
bdedb
bdddb
abbba

There are three rings in this matrix which are shown in the following matrix:

11111
12221
12321
12221
11111

When these rings are rotated once in the clockwise direction, the original matrix becomes

babbb
bdcda
bdecb
adddb
bbbab

.

Input

The input will be read from the terminal.
The first line of the input will contain a positive integer denoting the size of the square matrix.
The second line of the matrix contains a non-negative integer denoting the number of times the rotation should be applied.
The following lines will consist of words of lowercase english letters which describe the matrix row by row.

Output

The output should consist of words of lowercase english letters given line by line which describe the rotated matrix row by row.

Sample Input 1

4 1 aaaa bbbb cccc dddd

Sample Output 1

baaa ccba dcbb dddc

Sample Input 2

5 3 zaaaa aaaaa aaxza aaaaa aaaza

Sample Output 2

aaaza aaaaa aaxaa azaaa zaaaa

Assumptions and Constraints

The size of the square matrix will be between 1 and 50 inclusively.
The number rotations will be between 0 and 1000 inclusively.

Hints

You don't have to do all of the modifications directly on the matrix itself.
Feel free to use additional structures.
Usage of arrays and multidimensional arrays are highly suggested.
Use functions to reduce the complexity of the code.

Submission

Submit your source file (.c) through the submission system.