time limit per test
0.25 s
memory limit per test
64 MB
input
standard input
output
standard output

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?

Input

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

Output

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.

Examples
Input
1
2
3
Output
YES
Input
1
2
4
Output
YES
Input
1
3
5
Output
NO

数据处理一下,用java简单,用c++麻烦点

c++:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define Max 105
using namespace std;
int flag = 0;
char s[3][Max],ans[3][Max];
char s1[Max],s2[Max];
char *add(char *x,char *y)
{
    if(strlen(x) < strlen(y))
    {
        strcpy(s1,y);
        strcpy(s2,x);
    }
    else
    {
        strcpy(s1,x);
        strcpy(s2,y);
    }
    int d = 0,i = 0;
    for(i = 0;i < strlen(s2);i ++)
    {
        d += s1[i] - '0' + s2[i] - '0';
        s1[i] = d % 10 + '0';
        d /= 10;
    }
    while(s1[i])
    {
        d += s1[i] - '0';
        s1[i ++] = d % 10 + '0';
        d /= 10;
    }
    if(d)
    {
        s1[i ++] = d % 10 + '0';
        d /= 10;
        s1[i] = '\0';
    }
    return s1;
}
void dfs(int k)
{
    if(flag)return ;
    if(k == 3)
    {
        if(strcmp(add(ans[0],ans[1]),ans[2]) == 0)flag = 1;
        return ;
    }
    for(int i = 0;i < 3;i ++)
    {
        strcpy(ans[k],s[i]);
        dfs(k + 1);
    }
}
int main()
{
    for(int i = 0;i < 3;i ++)
    {
        cin>>s[i];
        reverse(s[i],s[i] + strlen(s[i]));
        for(int j = strlen(s[i]);j >= 1;j --)
        {
            if(s[i][j - 1] != '0')
            {
                s[i][j] = '\0';
                break;
            }
        }
    }
    dfs(0);
    if(flag)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

 

 

java:

import java.util.Scanner;
import java.math.BigInteger;;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int flag = 0;
        BigInteger d;
        BigInteger a[] = new BigInteger[3];
        for(int i = 0;i < 3;i ++)
            a[i] = sc.nextBigInteger();
        for(int i = 0;i < 3;i ++) {
            if(flag == 1)break;
            for(int j = 0;j < 3;j ++) {
                if(flag == 1)break;
                for(int k = 0;k < 3;k ++) {
                    if(flag == 1)break;
                    d = a[i];
                    if(a[i].add(a[j]).equals(a[k]))flag = 1;
                    a[i] = d;
                }
            }
        }
        if(flag == 1)System.out.println("YES");
        else System.out.println("NO");
    }
}