Statements
You are given three numbers. Is there a way to replace variables A, B and C with these numbers so the equality A + B = C is correct?
There are three numbers X1, X2 and X3 (1 ≤ Xi ≤ 10100), each on a separate line of input.
Output either "YES", if there is a way to substitute variables A, B and C with given numbers so the equality is correct, or "NO" otherwise.
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");
}