An Equation

本文介绍了一个简单的算法问题,即给定四个整数,判断是否存在一种排列方式使得两个数之和等于另外两个数之和。通过列举所有可能的组合情况,可以有效地解决这一问题。

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

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值