11154 - Swap Matrix row   

Description

Given a 5*5 matrix, your job is to swap two specific rows i and j (where 0 <= i,j < 5) several times.

 

For example:

 

Consider a matrix,

1 2 3 4 5

6 7 8 9 10

11 12 13 14 15

16 17 18 19 20

21 22 23 24 25

and the two rows (i,j) = (1,3).

 

After swap, the matrix will become

1 2 3 4 5

16 17 18 19 20

11 12 13 14 15

6 7 8 9 10

21 22 23 24 25

 

Input

The input consists of two parts.

 

The first part contains a 5*5 matrix.

 

The first line of the second part contains an integer N ( 0 < N <= 5 ), indicating the number of swaps.

In the next N lines, each contains 2 integers i,j ( 0 <= i,j < 5 ).

 

Hint:

You can use the following code to read input.

i=0;
while(i<5) {
    j=0;
    while(j<5) {
        scanf("%d",&matrix[i][j]);
        j++;
    }
    i++;
}
scanf("%d",&times);
while(times>0){
scanf("%d%d",&input[0],&input[1]);
…
times--;
…

Output

The final matrix.

Note that you need to print ‘\n’ at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss