提交时间:2023-09-13 13:13:45

运行 ID: 102311

#include<bits/stdc++.h> using namespace std; int n,m; int a[5001][5001]; bool check(int x,int y){ for(int i=1;i<=m;i++){ if(a[x][i]<a[y][i]) return 1; if(a[x][i]>a[y][i]) return 0; } } void solve(int x,int y){ for(int i=1;i<=m;i++){ swap(a[x][i],a[y][i]); } } signed main(){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; } } for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ if(!check(i,j)){ solve(i,j); } } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cout<<a[i][j]<<" "; } cout<<endl; } return 0; }