1587 - Box (UVA)

题目链接如下:

Online Judge

我的代码如下:

#include 
#include 
#include 
#include 

int w, h;
std::vector> vec;

bool cmp(const std::pair &a, const std::pair &b){
    return a.first != b.first ? a.first > b.first : a.second > b.second;
}

int main(){
    while(scanf("%d %d", &w, &h) == 2){
        vec.clear();
        for(int i = 0; i < 6; ++i){
            if(i != 0){
                scanf("%d %d", &w, &h);
            }
            if(w < h){
                std::swap(w, h);
            }
            vec.push_back({w, h});
        }
        sort(vec.begin(), vec.end(), cmp);
        if(vec[1] != vec[0] || vec[2] != vec[3] || vec[4] != vec[5] || vec[0].first != vec[2].first || vec[0].second != vec[4].first || vec[2].second != vec[4].second){
            printf("IMPOSSIBLE\n");
            continue;
        }
        printf("POSSIBLE\n");
    }
    return 0;
}

你可能感兴趣的:(UVA,c++,算法)