UVa1587 Box

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    set<int> s; // 12个数字中不能出现3个以上不同的值,最多只有三种值:长、宽、高
    int face[6];
    int i = 0, w, h;
    while (cin >> w >> h)
    {
        if (s.size() <= 3)
        {
            s.insert(w);
            s.insert(h);
            if (w > h)
                face[i] = (h << 16) | w; // 充分利用条件 1 <= w,h <= 10000
            else
                face[i] = (w << 16) | h;
        }
        
        if (++i == 6)
        {
            if (s.size() <= 3)
            {
                sort(face, face+6);
                for (i = 0; i < 6; i += 2)
                { // 判断是否存在3对相等的面
                    if (face[i] != face[i+1])
                        break;
                }
                if (i == 6)
                    cout << "POSSIBLE" << endl;
                else
                    cout << "IMPOSSIBLE" << endl;
            }
            else
            {
                cout << "IMPOSSIBLE" << endl;
            }
            i = 0;
            s.clear();
        }
    }

    return 0;
}

原文地址:https://www.cnblogs.com/danny1221/p/4601451.html