01: Matrix exchange line

Total time limit: 1000ms memory limit: 65536kB
Description
Given a 5x5 matrix (mathematically, a × r c is a matrix arranged in r rows by c columns of the rectangular array element), the n-th row and the m line switching, the output result of the exchange.

Input
Input 6 rows, each row of the matrix elements before 5 acts, elements and between the elements are separated by a space.
Line 6 comprises two integers m, n, separated by a space. (1 <= m, n < = 5)
output
matrix of the output after exchange, each row of the matrix elements of one row, with a space between the separate elements.
Sample input
. 1. 1 2 2 2
. 5. 3. 6. 7. 8
. 9. 3 0. 5. 3
. 7 2. 6. 1. 4
. 3. 4 0 2. 8
. 1. 5
sample output
. 3 2. 8. 4 0
. 5. 6. 7. 8. 3
. 9. 3 0. 5. 3
. 7 2 . 6. 4. 1
. 1. 1 2 2 2

#include<iostream>
using namespace std;
int main(){
	int a[6][6];
	for(int i=1;i<=5;i++)               //从1-5按次序输入 
	for(int j=1;j<=5;j++){
		cin>>a[i][j];
	}
	
	int m,n;
	cin>>m>>n;
	
	for(int j=1;j<=5;j++){              //以a[0]为临时变量,交换两行的值 
		a[0][j]=a[m][j];
		a[m][j]=a[n][j];
		a[n][j]=a[0][j];
	}
	
	
	for(int i=1;i<=5;i++){              //从1-5按次序输出 
		for(int j=1;j<=5;j++){
		cout<<a[i][j]<<' ';
		}
		cout<<endl;
	}
	
	return 0;
}
Published 36 original articles · won praise 0 · Views 358

Guess you like

Origin blog.csdn.net/weixin_44437496/article/details/103980035