Description

Given a5*5matrix (mathematically, an r×c matrix is a rectangular array arranged by r rows and c columns), swap the nth row and the mth row, and output the swapped result.

Input: The input consists of 6 lines; the first 5 lines are the elements of each row of the matrix, and elements are separated by a space.

The 6th line contains two integers m and n, separated by a space. (1 <= m,n <= 5) Output: Output the swapped matrix, with each row's elements on one line, elements separated by a space. Sample input:

1 2 2 1 2
5 6 7 8 3
9 3 0 5 3
7 2 1 4 6
3 0 8 2 4
1 5

Sample output:

3 0 8 2 4
5 6 7 8 3
9 3 0 5 3
7 2 1 4 6
1 2 2 1 2

Example

#include <iostream> using namespace std; int main() { int a[5][5], m, n, i, j; for (i=0; i<5; i++) for (j=0; j<5; j++) cin >> a[i][j]; cin >> m >> n; for (j=0; j<5; j++){ i = a[m-1][j]; a[m-1][j] = a[n-1][j]; a[n-1][j] = i; } for (i=0; i<5; i++){ for (j=0; j<5; j++){ cout << a[i][j] << " "; } cout << endl; } return 0; }

Original URL: http://noi.openjudge.cn/ch0108/01/