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");
}
}
随机推荐
- VSCode代码格式化自动换行问题
打开VS设置,添加如下代码 "vetur.format.defaultFormatter.html": "js-beautify-html", "ve ...
- FIFO设计验证经验谈
概述: FIFO是电路设计中非常重要的一个基本电路.一般的超大规模集成电路中,都会用到FIFO.所以,FIFO是每个SOC设计和验证工程师必须掌握的一种核心电路. FIFO电路又分为异步FIFO和同步 ...
- React Native之持久化存储(AsyncStorage、react-native-storage)的使用
AsyncStorage是一个简单的.异步的.持久化的Key-Value存储系统,它对于App来说是全局性的.这是官网上对它的介绍.可以知道,这个asyncstorage也是以键值对的形式进行存储数据 ...
- BUG: scheduling while atomic 分析【转】
本文转载自:https://blog.csdn.net/cfy_phonex/article/details/12090943 遇到一个典型的schedule问题. <3>[26578 ...
- Linux下多线程下载工具MWget和Axel使用介绍
linux运维在操作linux过程中,用得最多的linux下载工具想必一定是wget,没有看到哪一台服务器没装过wget的,或许有人使用ftp下载,也有人使用多线程的axel以及ProZilla,毫无 ...
- 使用Kali Linux 破解无线网
用到的工具 airmon-ngairodump-ngaireplay-ngaircrack-ng 过程 123456789101112131415161718192021222324 root@lm: ...
- resultMap结果集映射
resultMap结果集是用来定义sql查询的结果与java对象的映射关系.它主要解决2大问题: 1)可以解决POJO属性名和表结构的字段名不一致问题(甚至是 不是标准的驼峰命名法) 2)可以完成高级 ...
- NumPy排序、搜索和计数函数
NumPy - 排序.搜索和计数函数 NumPy中提供了各种排序相关功能. 这些排序函数实现不同的排序算法,每个排序算法的特征在于执行速度,最坏情况性能,所需的工作空间和算法的稳定性. 下表显示了三种 ...
- d2.js学习笔记(七)——动态SVG坐标空间
目标 在这一章,我们将学习如何使SVG坐标空间是动态的,这样我们的数据可视化不论数据是什么,都始终是可见的. 我们会使得SVG坐标空间尺度上调或下调来适于我们的数据. 三个SVG长方形 我们就从三个长 ...
- django Models 常用的字段和参数
1.字段 CharField IntegerField floatField DateTimeField DateField DecimalField 2.参数 null default choice ...