Uva 1587 Box

本文提供了一个使用 C++ 进行结构体数组输入、排序并判断特定条件是否满足的完整代码实例。该程序通过自定义比较函数实现排序,并检查排序后的元素是否成对相等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


AC代码:

#include<cstdio>
#include<algorithm>

using namespace std;

struct Node{
	int a,b;
}stu[33];

bool cmp(Node a,Node b)
{
	if(a.a!=b.a) return a.a<b.a;
	return a.b<b.b; 
}

int main()
{
	while(~scanf("%d%d",&stu[1].a,&stu[1].b))
	{
	    for(int i=2;i<=6;++i) scanf("%d%d",&stu[i].a,&stu[i].b);
	    for(int i=1;i<=6;++i)
	    {
	    	if(stu[i].a>stu[i].b) swap(stu[i].a,stu[i].b);
		}
		sort(stu+1,stu+7,cmp);
	//	for(int i=1;i<=6;++i) printf("%d %d %d\n",i,stu[i].a,stu[i].b);
		bool falg=true;
		for(int i=1;i<=5;i+=2){
			if(stu[i].a!=stu[i+1].a||stu[i].b!=stu[i+1].b) {
				falg=false; break;
			} 
		}
		if(falg) {
			if(stu[1].a==stu[3].a) {
				if(stu[3].b==stu[6].a){
					if(stu[1].b!=stu[6].b) falg=false; 
				}
				else if(stu[3].b==stu[6].b) {
					if(stu[1].b!=stu[6].a) falg=false; 
				}
				else falg=false;
			}//思考一下下面的代码多余 
//			else if(stu[1].a==stu[3].b) {
//				if(stu[3].a==stu[6].a) {
//					if(stu[1].b!=stu[6].b) falg=false;
//				}
//				else if(stu[3].a==stu[6].b) {
//					if(stu[1].b!=stu[6].a) falg=false;
//				}
//				else falg=false; 
//			}
			else {
				falg=false; 
			} 
		} 
		printf(falg?"POSSIBLE\n":"IMPOSSIBLE\n");
	}
	return 0;
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值