一种排序

 1 #include <algorithm>
 2 #include <cstdio>
 3 using namespace std;
 4 typedef struct node {
 5     int c,x,y;
 6 } node;
 7 node s[1010];
 8 
 9 bool cmp(node a,node b)
10 {
11     if(a.c<b.c)
12         return 1;
13     else
14     {
15         if(a.c==b.c)
16         {
17             if(a.x<b.x)
18                 return 1;
19             else
20             {
21                 if(a.x==b.x)
22                 {
23                     if(a.y<b.y)
24                         return 1;
25                     else
26                         return 0;
27                         
28                 }
29                 else
30                     return 0;
31             }
32         }
33         else
34             return 0;
35     }
36 }
37         
38     
39 int main()
40 {
41     int n,m;
42     scanf("%d",&n);
43     while(n--)
44     {
45         scanf("%d",&m);
46         for(int i=0;i<m;i++)
47         {
48             scanf("%d%d%d",&s[i].c,&s[i].x,&s[i].y);
49             if(s[i].x<s[i].y)
50                 swap(s[i].x,s[i].y);
51         }
52         sort(s,s+m,cmp);
53         printf("%d %d %d
",s[0].c,s[0].x,s[0].y);
54         for(int i=1;i<m;i++)
55         {
56             if(s[i-1].c==s[i].c&&s[i-1].x==s[i].x&&s[i-1].y==s[i].y)
57                 continue;
58             printf("%d %d %d
",s[i].c,s[i].x,s[i].y);
59         }
60     }
61     return 0;
62 }
63         
View Code
原文地址:https://www.cnblogs.com/WDKER/p/5459747.html