[KTU]Yet another A + B——高精度

本文介绍了如何解决A + B的问题,特别是在大数据情况下。通过分析输入的三个数X1、X2、X3,判断是否能构成A + B = C的等式。文章提到了使用字符数组进行加法运算,并利用DFS解决组合问题。在实现中,需要注意大数的逆置、前置0的处理和高位进位的特殊情况。
摘要由CSDN通过智能技术生成

Yet another A + B

一、原文

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

二、分析(收获)

1)本题为大数据加法,建议字符数组,利用strcmp好比较。当然结构体和string也是可以的。
2)利用DFS来巧妙处理组合问题。
3)细节上:1、对大数逆置,低位在前利于后续加法和比较
2、通过预处理(比较大小、处理前置0)和*char来传递数组
3、对于最高仍然有进位需要单独处理

三、代码
#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(
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值