题目:Ivan works at a factory that produces heavy machinery. He has a simple job -- he knocks up wooden boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular parallelepiped. Ivan uses six rectangular wooden pallets to make a box. Each pallet is used for one side of the box.
![](https://i-blog.csdnimg.cn/blog_migrate/0c954c5a07cedc25750883ec1ae0269b.jpeg)
Joe delivers pallets for Ivan. Joe is not very smart and often makes mistakes -- he brings Ivan pallets that do not fit together to make a box. But Joe does not trust Ivan. It always takes a lot of time to explain Joe that he has made a mistake.
Fortunately, Joe adores everything related to computers and sincerely believes that computers never make mistakes. Ivan has decided to use this for his own advantage. Ivan asks you to write a program that given sizes of six rectangular pallets tells whether it is possible to make a box out of them.
Input
Output
Sample Input
1345 2584 2584 683 2584 1345 683 1345 683 1345 2584 683
Sample Output
POSSIBLE
Source
#include<math.h>
int main(){
int a[12];//存储12 条边;
int sum;//统计不同边的个数;
int b[3];//不同边的值
int i,j,tag1,tag2,tag;
int c[6][2];//不同边组成的六个面
while(scanf("%d",&a[0])!=EOF){
sum=1;
tag=0;
b[0]=a[0];
for(i=1;i<12;i++){
scanf("%d",&a[i]);
for(j=0;j<i;j++){
if(a[i]==a[j]){
break;
}
}
if(j==i){
if(sum<3){
b[sum]=a[i];
}
sum++;
}
}
if(sum>3){printf("IMPOSSIBLE\n");continue;}//边大于3
if(sum==1){ printf("POSSIBLE\n");continue;}//边等于1
if(sum==2){//边等于2
tag1=0;
tag2=0;
tag=0;
for(i=0;i<12;i++){
if(a[i]==b[0]){
tag1++;
}
if(a[i]==b[1]){
tag2++;
}
}//找出记录两条边各自相同的数目
if(tag1>tag2){//说明记录的值个数b[0]>b[1];下面是够成的六个面;
c[0][0]=b[0];c[0][1]=b[1];
c[1][0]=b[0];c[1][1]=b[1];
c[2][0]=b[0];c[2][1]=b[1];
c[3][0]=b[0];c[3][1]=b[1];
c[4][0]=b[0];c[4][1]=b[0];
c[5][0]=b[0];c[5][1]=b[0];
}
if(tag1<tag2){//b[1]>b[0]
c[0][0]=b[1];c[0][1]=b[1];
c[1][0]=b[1];c[1][1]=b[1];
c[2][0]=b[0];c[2][1]=b[1];
c[3][0]=b[0];c[3][1]=b[1];
c[4][0]=b[0];c[4][1]=b[1];
c[5][0]=b[0];c[5][1]=b[1];
}
for(i=0;i<6;i++){//自己组合的边与所给边对比,并把比过相等的置0;
for(j=0;j<12;j+=2){
if((a[j]==c[i][0]&&a[j+1]==c[i][1])||(a[j+1]==c[i][0]&&a[j]==c[i][1])){
a[j]=0;
a[j+1]=0;
break;
}
}
}
for(j=0;j<12;j+=2){
if(a[j]!=0){
tag=1;
break;
}
}
if(tag==0){
printf("POSSIBLE\n");continue;
}
printf("IMPOSSIBLE\n");continue;
}
if(sum==3){
c[0][0]=b[0];c[0][1]=b[1];
c[1][0]=b[0];c[1][1]=b[2];
c[2][0]=b[1];c[2][1]=b[0];
c[3][0]=b[1];c[3][1]=b[2];
c[4][0]=b[2];c[4][1]=b[0];
c[5][0]=b[2];c[5][1]=b[1];
for(i=0;i<6;i++){
for(j=0;j<12;j+=2){
if((a[j]==c[i][0]&&a[j+1]==c[i][1])||(a[j+1]==c[i][0]&&a[j]==c[i][1])){
a[j]=0;
a[j+1]=0;
break;
}
}
}
for(j=0;j<12;j+=2){
if(a[j]!=0){
tag=1;
break;
}
}
if(tag==1){printf("IMPOSSIBLE\n");continue;}
printf("POSSIBLE\n");continue;
}
}
return 0;
}
#include<string.h>
int main()
{
int t,i,j;
int a[6][2],b[3][2];
while(scanf("%d%d",&a[0][0],&a[0][1])!=EOF){
if(a[0][0]>a[0][1]){t=a[0][0];a[0][0]=a[0][1];a[0][1]=t;}
for(i=1;i<6;i++){
scanf("%d%d",&a[i][0],&a[i][1]);
if(a[i][0]>a[i][1]){t=a[i][0];a[i][0]=a[i][1];a[i][1]=t;}
}
t=0;
for(i=0;i<5;i++){
for(j=i+1;j<6;j++){
if(a[i][0]==a[j][0]&&a[i][1]==a[j][1]&&a[i][0]!=0){
b[t][0]=a[i][0];
b[t][1]=a[i][1];
a[i][0]=0;
a[i][1]=0;
a[j][0]=0;
a[j][1]=0;
t++;
break;
}
}
}
if(t==3){
t=0;
for(i=1;i<3;i++){
if(b[0][0]>b[i][0]){
t=b[0][0];b[0][0]=b[i][0];b[i][0]=t;
t=b[0][1];b[0][1]=b[i][1];b[i][1]=t;
}
if(b[0][0]==b[i][0]&&b[0][1]>b[i][1]){
t=b[0][1];b[0][1]=b[i][1];b[i][1]=t;
}
}
if(b[0][1]==b[1][0]&&b[2][0]==b[0][0]&&b[2][1]==b[1][1]){t=1;}
if(b[0][1]==b[2][0]&&b[1][0]==b[0][0]&&b[1][1]==b[2][1]){t=1;}
if(t==1){printf("POSSIBLE\n");}
else{printf("IMPOSSIBLE\n");}
}
else{
printf("IMPOSSIBLE\n");
}
}
return 0;
}
这是道水题卡了差不多一天,还是很菜,依然继续努力;