Yet another A + B
0.25 s
64 MB
standard input
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?
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.
1
2
3
YES
1
2
4
YES
1
3
5
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");
}
}
随机推荐
- 【笔记】c++文件
1.文件. #include <iostream> #include <cstdio> #include <string> #include <cstring ...
- jQuery鼠标滑动切换焦点图
在线演示 本地下载
- HTML5抽奖转盘
在线演示 本地下载
- 使用AutoIT检测已安装软件,并将结果保存在桌面
$file = "\adobe安装列表.txt" $regedit1 = "hklm64\SOFTWARE\Wow6432Node\Microsoft\Windows\C ...
- QT添加资源文件,并为工具栏添加图片
1.右键工程,添加新文件,QT,QT Resource File. 2.选择res,添加前缀,添加文件,(把图片放在文件夹里,把文件夹放在工程目录下)选择图片 3.在ui中,下方有个Action Ed ...
- NaviCat Primium远程连接Oracle 11g数据库操作方法
说明:作者使用的系统是windows 10 64位系统,使用的软件及插件都是基于64位系统进行安装.一. 软件准备 1.windows 10 64位 操作系统 2.NaviCat Primium 11 ...
- COS-5资源分配与调度
操作系统是用户和计算机的接口,同时也是计算机硬件和其他软件的接口.操作系统的功能包括管理计算机系统的硬件.软件及数据资源,控制程序运行,改善人机界面,为其它应用软件提供支持,让计算机系统所有资源最大限 ...
- Linux(CentOS)中常用软件安装,使用及异常——XManager, 中文支持,JDK
XManager图形化界面远程连接 采用Xshell的方式可以不用在CentOS系统中配置即可以相连,主要原理就是SSH连接的方式,但是XManager图形化界面远程连接是需要修改CentOS系统的. ...
- JavaScript 打印控件
JavaScript 打印控件 github地址 https://github.com/DoersGuild/jQuery.print 使用前需要引入jQuery $("#mapDiv&qu ...
- oracle: 分割字符串,或者查找字段里面的关键字(关键字1,关键字2,关键字3)
表中有一个字段:keyword, keyword里面的存储的字符一般是:[关键字1,关键字2,关键字3] 那么,在搜索的时候,不能用like 来模糊查询,因为这样会,多查询出一下不相干的关键字, hi ...