高精度 I - Yet another A + B

    xiaoxiao2021-03-25  205

    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"); }
    转载请注明原文地址: https://ju.6miu.com/read-355.html

    最新回复(0)