首页 > 代码库 > uva1587

uva1587

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[8][4],x=0,flag=0,b[20],y=0,z=0,c[20];
    while(~scanf("%d%d",&a[x++][0],&a[x][1]))
    {
        if(a[0][0]==a[x-1][0]||a[0][0]==a[x-1][1])
        {
            flag++;
            b[y++]=x-1;
            if(a[0][0]==a[x-1][0])
                b[y++]=1;
            else
                b[y++]=0;
        }
        else
        {
            c[z++]=x-1;
        }
        if(x==6)
        {
            if(flag<4)
                printf("IMPOSSIBLE\n");
            else
            {
                int flag1=0,ch=0,ku=0;
                for(int i=0; i<6; i++,i++)
                    for(int j=i+2; j<8; j++,j++)
                        if(a[b[i]][b[i+1]]==a[b[j]][b[j+1]])
                        {
                            if(ch)
                                ku=a[b[i]][b[i+1]];
                            else
                                ch=a[b[i]][b[i+1]];
                            flag1++;

                        }
                if(flag1<2)
                    printf("IMPOSSIBLE\n");
                else
                {
                    for(int i=0; i<2; i++)
                        if((ku==a[c[i]][0]&&ch==a[c[i]][1])||(a[c[i]][1]==ku&&a[c[i]][0]==ch))
                            flag1++;
                    if(flag1<4)
                        printf("IMPOSSIBLE\n");
                    else
                        printf("POSSIBLE\n");
                }

 

            }

            x=0;
            flag=0;
            y=0;
            z=0;

        }
    }
    return 0;
}

uva1587