UVa1587

#pragma warning(disable:4996)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include   
#include 
#include  
#include
#include
#include
#include


using namespace std;
using namespace std::placeholders;
int block[6][2];

int main()
{
    while (cin >> block[0][0])
    {
        int count = 0;
        cin >> block[0][1];
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 0; j <= 1; j++)
                cin >> block[i][j];
        }
        for (int i = 0; i <= 5; i++)
        {
            if (block[i][0] > block[i][1])
                swap(block[i][0], block[i][1]);
        }
        for (int i = 0; i <= 5; i++)
        {
            for (int j = i; j <= 5; j++)
            {
                if (block[i][0] > block[j][0])
                {
                    swap(block[i][0], block[j][0]);
                    swap(block[i][1], block[j][1]);
                }   
            }
        }
        for (int i = 0; i <= 5; i++)
        {
            for (int j = i; j <= 5; j++)
            {
                if (block[i][0] == block[j][0] && block[i][1] > block[j][1])
                {
                    swap(block[i][1], block[j][1]);
                }
            }
        }
        for (int i = 1; i <= 5; i++)
        {
                if (block[0][0] == block[i][0] && block[0][1] == block[i][1])
                {
                    block[i][0] = 0;
                    block[i][1] = 0;
                    count++;
                    goto loop1;
                }
        }
    loop1:
        int ans = 0;
        int temp[2] = { 0 };
        for (int i = 1; i <= 5; i++)
        {
                if (block[0][0] == block[i][0])
                {
                    block[i][0] = 0;
                    ans++;
                    temp[ans - 1] = block[i][1];
                    block[i][1]=0;
                    if (ans == 2)
                    {
                        goto  loop2;
                    }
                }
        }
    loop2:
        ans = 0;
        if (temp[0] == temp[1])
            count++;
        for (int i = 1; i <= 5; i++)
        {
                if (block[0][1] == block[i][0] && block[i][1]== temp[1])
                {
                    block[i][1] = 0;
                    block[i][0] = 0;
                    ans++;
                    if (ans == 2)
                    {
                        count++;
                        goto loop3;
                    }
                }
        }
    loop3:
        if (count == 3)
            cout << "POSSIBLE" << endl;
        else
            cout << "IMPOSSIBLE" << endl;   
    }
    return 0;
}

优化代码

#pragma warning(disable:4996)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include   
#include 
#include  
#include
#include
#include
#include


using namespace std;
using namespace std::placeholders;
int block[6][2];

int main()
{
    while (cin >> block[0][0])
    {
        int count = 0;
        cin >> block[0][1];
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 0; j <= 1; j++)
                cin >> block[i][j];
        }
        for (int i = 0; i <= 5; i++)
        {
            if (block[i][0] > block[i][1])
                swap(block[i][0], block[i][1]);
        }
        for (int i = 0; i <= 5; i++)
        {
            for (int j = i; j <= 5; j++)
            {
                if (block[i][0] > block[j][0])
                {
                    swap(block[i][0], block[j][0]);
                    swap(block[i][1], block[j][1]);
                }   
            }
        }
        for (int i = 0; i <= 5; i++)
        {
            for (int j = i; j <= 5; j++)
            {
                if (block[i][0] == block[j][0] && block[i][1] > block[j][1])
                {
                    swap(block[i][1], block[j][1]);
                }
            }
        }
        if (block[0][0] == block[1][0] && block[2][0] == block[3][0] && block[0][0] == block[2][0] && block[0][1]==block[1][1]&&block[4][0]==block[5][0]&&block[0][1]==block[4][0]&&block[2][1]==block[3][1]&&block[4][1]==block[5][1]&&block[2][1]==block[4][1])
            cout << "POSSIBLE" << endl;
        else
            cout << "IMPOSSIBLE" << endl;   
    }
    return 0;
}

你可能感兴趣的:(UVA)