习题3-10 盒子 UVa1587

1.题目描述:点击打开链接

2.解题思路:先令输入的宽<长,然后找到三对矩形的长宽依次放入mark数组,看他们是否构成了长宽高的所有组合即可。

3.代码:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
int a[6][2];
int mark[6];

int main()
{
	while (scanf("%d%d", &a[0][0], &a[0][1]) == 2)
	{
		for (int i = 1; i < 6; i++)
			scanf("%d%d", &a[i][0], &a[i][1]);
		for (int i = 0; i < 6; i++)
		if (a[i][0]>a[i][1])
		{
			int t = a[i][0];
			a[i][0] = a[i][1];
			a[i][1] = t;
		}
		int n = 0;
		for (int i = 0; i < 5; i++)
		{
			if (!a[i][0]) continue;
			for (int j = i + 1; j < 6; j++)
			{
				if (!a[j][0]) continue;
				if (a[i][0] == a[j][0] && a[i][1] == a[j][1])
				{
					mark[n++] = a[i][0];
					mark[n++] = a[i][1];
					a[j][0] = 0;
					break;
				}
			}
		}
		if (n != 6)
			printf("IMPOSSIBLE\n");
		else
		{
			if (mark[0] == mark[2])
			{
				if ((mark[1] == mark[4] && mark[3] == mark[5]) || (mark[1] == mark[5] && mark[3] == mark[4]))
				{
					printf("POSSIBLE\n");
					goto x1;
				}
				else printf("IMPOSSIBLE\n");
			}
			else if (mark[0] == mark[3])
			{
				if ((mark[1] == mark[4] && mark[2] == mark[5]) || (mark[1] == mark[5] && mark[2] == mark[4]))
				{
					printf("POSSIBLE\n");
					goto x1;
				}
				else printf("IMPOSSIBLE\n");
			}
			else if (mark[1] == mark[2])
			{
				if ((mark[0] == mark[4] && mark[3] == mark[5]) || (mark[0] == mark[5] && mark[3] == mark[4]))
				{
					printf("POSSIBLE\n");
					goto x1;
				}
				else printf("IMPOSSIBLE\n");
			}
			else if (mark[1] == mark[3])
			{
				if ((mark[0] == mark[4] && mark[2] == mark[5]) || (mark[0] == mark[5] && mark[2] == mark[4]))
				{
					printf("POSSIBLE\n");
					goto x1;
				}
				else printf("IMPOSSIBLE\n");
			}
			else printf("IMPOSSIBLE\n");
		}
	x1:;
	}
	return 0;
}



你可能感兴趣的:(uva)