1 条题解

  • 0
    @ 2022-12-2 21:51:33

    通过改变输出顺序实现

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int a[6][6];
    	for(int i=1;i<=5;i++)
    		for(int j=1;j<=5;j++)
    			cin>>a[i][j];
    	int n,m;//交换第n行与第m行
    	cin>>n>>m;
    	//输出
    	for(int i=1;i<=5;i++){
    		for(int j=1;j<=5;j++){
    			if(i==n)
    				cout<<a[m][j]<<" ";
    			else if(i==m)
    				cout<<a[n][j]<<" ";
    			else
    				cout<<a[i][j]<<" ";
    		}
    		cout<<"\n";
    	} 
    	return 0;
    }
    
    

    改变数组

    #include<bits/stdc++.h>
    using namespace std;
    int a[10][10];
    int x,y;
    int main(){
        for(int i=1;i<=5;i++)
            for(int j=1;j<=5;j++)
                cin>>a[i][j];
        cin>>x>>y;
        for(int j=1;j<=5;j++)
            swap(a[x][j], a[y][j]);
        for(int i=1;i<=5;i++){
            for(int j=1;j<=5;j++){
                cout<<a[i][j]<<" ";
    		}
            cout<<"\n";
        }
        return 0;
    }
    /*
    1,1  1,2  1,3  1,4  1,5
    2,1  2,2  2,3  2,4  2,5
    3,1  3,2  3,3  3,4  3,5
    4,1  4,2  4,3  4,4  4,5
    5,1  5,2  5,3  5,4  5,5
    */
    
    • 1

    信息

    ID
    339
    时间
    1000ms
    内存
    128MiB
    难度
    2
    标签
    (无)
    递交数
    118
    已通过
    72
    上传者