An Equation (ZCMU暑期提高六)

Given four integers, your task is to find out whether there is a permutation A, B, C, D, such that the equation A+B=C+D holds.

For example, if there are four integers 2,5,6,3, we could find out an equation 2+6=3+5 that satisfies A+B=C+D. If there are four integers 1,2,4,9, we could not find out any equation that satisfies A+B=C+D.

If we could use these four integers to form an equation that satisfies A+B=C+D, please output “Yes”, otherwise output “No” instead.

Input

The first line of the input contains an integer T (T <= 10), indicating the number of cases. Each case begins with a line containing four integers a,b,c,d (1 <= a,b,c,d <= 10).

Output

For each test case, print a line containing the test case number (beginning with 1) and whether there is a permutation A, B, C, D, such that the equation A+B=C+D holds.

Sample Input

4
2 3 5 6
4 3 2 1
2 1 1 2
1 2 4 9

Sample Output

Case 1: Yes
Case 2: Yes
Case 3: Yes
Case 4: No

 

模拟题,不是手速慢就是我写的太冗余了

应该是冗余了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int ca;
int main()
{
	int T;
	scanf("%d", &T);
	while (T--) {
		ca++;
		int a, b, c, d;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		int x1 = a + b;
		int x2 = a + c;
		int x3 = a + d;
		int x4 = b + c;
		int x5 = b + d;
		int x6 = c + d;
		int  flag = 0;
		if (x1 == x2)  flag = 1;
		else if (x1 == x3) flag = 1;
		else if (x1 == x4) flag = 1;
		else if (x1 == x5) flag = 1;
		else if (x1 == x6) flag = 1;
		else if (x2 == x3) flag = 1;
		else if (x2 == x4) flag = 1;
		else if (x2 == x5) flag = 1;
		else if (x2 == x6) flag = 1;
		else if (x3 == x4) flag = 1;
		else if (x3 == x5) flag = 1;
		else if (x3 == x6) flag = 1;
		else if (x4 == x5) flag = 1;
		else if (x4 == x6) flag = 1;
		else if (x5 == x6) flag = 1;
		if (flag) printf("Case %d: Yes\n", ca);
		else printf("Case %d: No\n", ca);


	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值