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");
}
}
随机推荐
- java的arrayCopy用法
java的arrayCopy用法 final , ); //System.arraycopy(samplesConverted, 0, bytes, 0, 1024); 先贴上语法: publ ...
- 20145235李涛《网络对抗》Exp2 后门原理与实践
Windows获得Linux Shell Linux获得windows shell 实验内容 使用netcat获取主机操作shell,cron启动 使用socat获取主机shell,任务计划启动 使用 ...
- 部署 LAMP (CentOS 7.2),摘自阿里云,方便查看使用
原文地址:https://help.aliyun.com/document_detail/50774.html?spm=5176.product25365.6.728.C9s3V8 简介 LAMP指L ...
- NumPy线性代数
NumPy - 线性代数 NumPy 包包含numpy.linalg模块,提供线性代数所需的所有功能. 此模块中的一些重要功能如下表所述. 序号 函数及描述 1. dot 两个数组的点积 2. vdo ...
- 用TestPMD测试DPDK性能和功能
本文介绍了数据平面开发工具包(DPDK)TestPMD应用程序,展示了如何构建和配置TestPMD, 以及如何用它来检查使用DPDK的不同网络设备的性能和功能. TestPMD是一个使用DPDK软件包 ...
- 使用springmvc的时候报错NoSuchBeanDefinitionException: No qualifying bean of type
NoSuchBeanDefinitionException: No qualifying bean of type 其实我至今都不知道错误的根源在哪里,<context:component-sc ...
- yii2: 上传图片,生成目录
1.单个文件上传 首先建立一个模型models/UploadForm.php,内容如下 namespace app\models; use yii\base\Model; use yii\web\Up ...
- 20165332实验一 Java开发环境的熟悉
实验一 Java开发环境的熟悉 一.Java开发环境的熟悉-1 1.实验要求: 0 参考实验要求: 1 建立"自己学号exp1"的目录 : 2 在"自己学号exp1&qu ...
- Xcode 8 GM 编译缺失 /Users/usr/lib/libresolv.9.dylib
原因是操作系统的文件与手机需要的不同. 解决办法是将iOS DeviceSupport里当前手机版本的Symbols的libresolv.9.dylib文件,代替编译失败项目的Build Phases ...
- opencv:访问像素
a.使用指针 #include <opencv.hpp> using namespace cv; using namespace std; int main() { //指针访问每个像素并 ...