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);
}
}