uva 1587 Box

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef struct node
{
    int w;
    int l;
}r[6];
void swap0(int a,int b)
{
    int t;
    t=a;
    a=b;
    b=t;
}
void swap1(node r[6])
{
    for(int i=0;i<6;i++)
    {
        if(r[i].w>r[i].l)
        {
            r[i].w=r[i].w+r[i].l;
            r[i].l=r[i].w-r[i].l;
            r[i].w=r[i].w-r[i].l;
        }
    }
}
void swap2(node r[6])
{
    for(int i=0;i<5;i++)
    {
        int flag=i;
        for(int j=i+1;j<6;j++)
        {
            if(r[flag].w>r[j].w) flag=j;
            if(r[flag].w==r[j].w)
            {
                if(r[flag].l>r[j].l) flag=j;
            }
        }
        swap(r[flag].w,r[i].w);
        swap(r[flag].l,r[i].l);
    }
}
int main()
{
    node r[6];
    while(scanf("%d%d",&r[0].w,&r[0].l)!=EOF)
    {
        int cnt=0;
        for(int i=1;i<6;i++)
            cin>>r[i].w>>r[i].l;
        swap1(r);
        swap2(r);
        for(int i=0;i<6;i=i+2)
            if(r[i].w==r[i+1].w&&r[i].l==r[i+1].l) cnt++;
        if(cnt==3)
        {
            int p[6];
            for(int i=0;i<6;i=i+2)
            {
                p[i]=r[i].w;
                p[i+1]=r[i].l;
            }
            sort(p,p+6);
            int count=0;
            for(int i=0;i<6;i=i+2)
                if(p[i]==p[i+1]) count++;
            for(int i=0;i<6;i++)
                if(p[i]==0) count=0;
            if(count==3) cout<<"POSSIBLE"<<endl;
            else cout<<"IMPOSSIBLE"<<endl;
        }
        else cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

你可能感兴趣的:(uva 1587 Box)