Dsecription
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<stdio.h>
int main()
{
int T,kase=1;
scanf("%d",&T);
while(T--)
{
int a,b,c,d,flag=0;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a+b==c+d)
flag=1;
else if(a+c==b+d)
flag=1;
else if(a+d==b+c)
flag=1;
if(flag)
printf("Case %d: Yes\n",kase);
else
printf("Case %d: No\n",kase);
kase+=1;
}
return 0;
}