高精度 I - Yet another A + B


Statements

You are given three numbers. Is there a way to replace variables AB and C with these numbers so the equality A + B = C is correct?

Input

There are three numbers X1X2 and X3 (1 ≤ Xi ≤ 10100), each on a separate line of input.

Output

Output either "YES", if there is a way to substitute variables AB and C with given numbers so the equality is correct, or "NO" otherwise.

Example
Input
1
2
3
Output
YES
Input
1
2
4
Output
YES
Input
1
3
5
Output
NO
#include <bits/stdc++.h>
using namespace std;


#define LL long long
#define INF 1E4 * 1E9
#define pi acos(-1)
#define endl '\n'
#define me(x) memset(x,0,sizeof(x));
const int maxn=1e3+5;
const int maxx=1e6+5;


void bigIntergerAdd(string &num, string add) 
{
	int goBit = 0; // 存放进位
	// 先交换下顺序  加数的位数要比较少
	if (num.length() < add.length())
    {
		string tmp = num;
		num = add;
		add = tmp;
	}
	string tmp (num.length() - add.length(), '0');
	add = tmp + add;
	// 利用string的+号特性  不采用逆序相加法
	int len1 = num.length(), len2 = add.length();
	for (int i = len1 -1 ; i>= 0; --i) 
    {
		int tmp =  ((num[i] - '0') + (add[i] - '0') + goBit) ;
		num[i] = tmp% 10 + '0';
		goBit = tmp/10;
	}
	// 特殊情况处理
	if (goBit != 0)
		num.insert(0, string(1, (char)goBit +'0'));
}


int main()
{
	string s1,s2,s3;
	string result;
	int i =0;
	cin>>s1>>s2>>s3;
    result=s1;
    bigIntergerAdd(result,s1);
    if(result==s2||result==s3)
    {
        puts("YES");
        return 0;
    }
    result=s2;
    bigIntergerAdd(result, s2);
    if(result==s1||result==s3)
    {
        puts("YES");
        return 0;
    }
    result=s3;
    bigIntergerAdd(result, s3);
    if(result==s2||result==s1)
    {
        puts("YES");
        return 0;
    }
    result=s2;
    bigIntergerAdd(result, s3);
    if(result==s1)
    {
        puts("YES");
        return 0;
    }
    result=s1;
    bigIntergerAdd(result, s3);
    if(result==s2)
    {
        puts("YES");
        return 0;
    }
    result=s2;
    bigIntergerAdd(result, s1);
    if(result==s3)
    {
        puts("YES");
        return 0;
    }
    puts("NO");


}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值