Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created May 23, 2015 06:48
Show Gist options
  • Save henrybear327/53c5b9f2e0b9ccb2b830 to your computer and use it in GitHub Desktop.
Save henrybear327/53c5b9f2e0b9ccb2b830 to your computer and use it in GitHub Desktop.
struct qosrt
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct data {
int front;
int back;
} all[50000];
int cmp(const void *a, const void *b)
{
//按照front由小到大,果front相同,按照back由小到大
if (((struct data *)a)->front != ((struct data *)b)->front)
return ((struct data *)a)->front - ((struct data *)b)->front;
else
return ((struct data *)a)->back - ((struct data *)b)->back;
}
int main()
{
int input1;
scanf("%d", &input1);
while (input1--) {
int input2;
int i;
scanf("%d", &input2);
for (i = 0; i < input2; i++) {
scanf("%d %d", &all[i].front, &all[i].back);
// printf("%d %d\n", all[i].front, all[i].back);
}
qsort(all, input2, sizeof(struct data), cmp);
printf("\n\n");
for (i = 0; i < input2; i++) {
printf("%d %d\n", all[i].front, all[i].back);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment