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 = ;
char s[][Max],ans[][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 = ,i = ;
for(i = ;i < strlen(s2);i ++)
{
d += s1[i] - '' + s2[i] - '';
s1[i] = d % + '';
d /= ;
}
while(s1[i])
{
d += s1[i] - '';
s1[i ++] = d % + '';
d /= ;
}
if(d)
{
s1[i ++] = d % + '';
d /= ;
s1[i] = '\0';
}
return s1;
}
void dfs(int k)
{
if(flag)return ;
if(k == )
{
if(strcmp(add(ans[],ans[]),ans[]) == )flag = ;
return ;
}
for(int i = ;i < ;i ++)
{
strcpy(ans[k],s[i]);
dfs(k + );
}
}
int main()
{
for(int i = ;i < ;i ++)
{
cin>>s[i];
reverse(s[i],s[i] + strlen(s[i]));
for(int j = strlen(s[i]);j >= ;j --)
{
if(s[i][j - ] != '')
{
s[i][j] = '\0';
break;
}
}
}
dfs();
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");
}
}

随机推荐

  1. 【笔记】IntelliJ IDEA配置Hibernate

    参考:imooc:http://www.imooc.com/video/7706 1.创建Hibernate的配置文件. 将依赖包导入项目.http://blog.csdn.net/a15337525 ...

  2. SVN使用—高级用法

    一.SVN分支 Branch 选项会给开发者创建出另外一条线路.当有人希望开发进程分开成两条不同的线路时,这个选项会非常有用. 情景: 比如项目 demo 下有两个小组,svn 下有一个 trunk ...

  3. tcp连接的建立与释放

    1.TCP是面向连接的协议. 运输连接时用来传送TCP报文的.TCP运输连接的建立和释放是每一次面向连接的通信中必不可少的过程.因此,运输链接就有三个阶段,即:连接建立.数据传送和连接释放. 在TCP ...

  4. hdu 5777 domino 贪心

    domino Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem ...

  5. 谈谈你对Glide和Picasso他们的对比的优缺点

    1.Picasso和Glide的withi后面的参数不同 Picasso.with(这里只能传入上下文)     . Glide.with,后面可以传入上下文,activity实例,FragmentA ...

  6. 读jQuery之六(缓存数据)

    很多同学在项目中都喜欢将数据存储在HTMLElement属性上,如 1 2 3 4 <div data="some data">Test</div> < ...

  7. angular2-scroll-module

    这篇介绍一下,写一个自己的angular2滚动监听插件 目录结构: /scrollModule: ztw-scroll.module.ts; scrollBind.directive.ts; scro ...

  8. linux的文件

    今日感慨:linux根目录下的文件夹含义 bin的知识,二进制文件,其用途依系统或应用而定 . 也就是说,一般来讲是机器代码,汇编语言编译后的结果,(DOS下汇编语言编译后与.com文件相类似),用d ...

  9. yii2: oralce中文,有的汉字是2个字节,有的汉字是3个字节

    yii2: oralce中文,有的汉字是2个字节,有的汉字是3个字节 请用mb_substr转成1个英文字节

  10. Confluence 6 配置系统属性

    在这个页面中描述 Confluence 启动时如何设置 Java 属性和其他选项. 请查看 How to fix out of memory errors by increasing availabl ...