#28759: CPP


11030067@mail.hpsh.tp.edu.tw (和平110級鄧雨珊)

學校 : 臺北市立和平高級中學
編號 : 163096
來源 : [61.64.210.174]
最後登入時間 :
2022-10-23 16:54:59
d550. 物件排序 | From: [219.85.177.13] | 發表日期 : 2021-12-30 22:16

#include <iostream>
#include <algorithm>
using namespace std;
 
int n,m,s[10000][200],h[10000];
 
bool cmp(int x,int y) {
int i;
for (i=0;i<m;i++) {
if (s[x][i]!=s[y][i]) return s[x][i]<s[y][i];
}
return 1;
}
 
int main() {
int i,j;
while (~scanf("%d%d",&n,&m)) {
for (i=0;i<n;i++) {
h[i]=i;
for (j=0;j<m;j++) scanf("%d",&s[i][j]);
}
sort(h,h+n,cmp);
for (i=0;i<n;i++) {
for (j=0;j<m;j++) printf("%d ",s[h[i]][j]);
printf("\n");
}
}
}
 
ZeroJudge Forum