结构体三级排序(nyoj 17)

时间:2022-12-12 19:43:57

题目链接 :http://acm.nyist.net/JudgeOnline/problem.php?pid=17&rec=rec

#include<stdio.h>
#include<algorithm>
using namespace std;

typedef struct Node
{
    int a,b,c;
};
bool cmp(Node s1,Node s2)
{
    if(s1.a!=s2.a)    return s1.a<s2.a;
    else if(s1.b!=s2.b)    return s1.b<s2.b;
    else     return s1.c<s2.c;
}
int main()
{
    int T,x,i,t,j;
    Node s[1001];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&x);
        for(i=0;i<x;i++)
        {
            scanf("%d%d%d",&s[i].a,&s[i].b,&s[i].c);
            if(s[i].b<s[i].c)
                t=s[i].b,s[i].b=s[i].c,s[i].c=t;
        }
        sort(s,s+x,cmp);
        for(i=0;i<x;i++)
            if(!(s[i].a==s[i+1].a && s[i].b==s[i+1].b && s[i].c==s[i+1].c))
                printf("%d %d %d\n",s[i].a,s[i].b,s[i].c);
    }
    return 0;
}