查看所给的数据是否能组成长方体,我的思路:三个值 a b h 假设a>b>h,那么能组成长方体的话,肯定是三组相同的数据,对他们进行排序,查看相隔的数据是否相等。最大的边是a b,其次 a h,最后b h,分别进行比较,成立的话就是可以组成,否则就是不可以。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct box
{
int max;
int min;
int v;
};
bool operator== (box a,box b)
{
if(a.max==b.max && a.min==b.min)
return true;
return false;
}
bool comp(box a,box b)
{
return a.v>b.v;
}
int main(int argc, char const *argv[])
{
box data[6];
int a,b;
int i=0;
while(cin>>a>>b)
{
i=i%6;
data[i].max=a>=b?a:b;
data[i].min=a<b?a:b;
data[i].v=a+b;
i++;
if(i!=6)
continue;
sort(data,data+6,comp);
bool flag=true;
for(int j=0; j<5; j+=2)
{
if(data[j]==data[j+1]);
else
flag=false;
}
if(flag)
{
if(data[0].max==data[2].max && data[0].min==data[4].max && data[2].min==data[4].min)
cout<<"POSSIBLE\n";
else
cout<<"IMPOSSIBLE\n";
}
else
cout<<"IMPOSSIBLE\n";
}
return 0;
}