高精度 I - Yet another A + B
2017-03-08 11:01
447 查看
Statements
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.
Example
Input
Output
Input
Output
Input
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.
Example
Input
1 2 3
Output
YES
Input
1 2 4
Output
YES
Input
1 3 5
Output
NO
#include <bits/stdc++.h> using namespace std; #define LL long long #define INF 1E4 * 1E9 #define pi acos(-1) #define endl '\n' #define me(x) memset(x,0,sizeof(x)); const int maxn=1e3+5; const int maxx=1e6+5; void bigIntergerAdd(string &num, string add) { int goBit = 0; // 存放进位 // 先交换下顺序 加数的位数要比较少 if (num.length() < add.length()) { string tmp = num; num = add; add = tmp; } string tmp (num.length() - add.length(), '0'); add = tmp + add; // 利用string的+号特性 不采用逆序相加法 int len1 = num.length(), len2 = add.length(); for (int i = len1 -1 ; i>= 0; --i) { int tmp = ((num[i] - '0') + (add[i] - '0') + goBit) ; num[i] = tmp% 10 + '0'; goBit = tmp/10; } // 特殊情况处理 if (goBit != 0) num.insert(0, string(1, (char)goBit +'0')); } int main() { string s1,s2,s3; string result; int i =0; cin>>s1>>s2>>s3; result=s1; bigIntergerAdd(result,s1); if(result==s2||result==s3) { puts("YES"); return 0; } result=s2; bigIntergerAdd(result, s2); if(result==s1||result==s3) { puts("YES"); return 0; } result=s3; bigIntergerAdd(result, s3); if(result==s2||result==s1) { puts("YES"); return 0; } result=s2; bigIntergerAdd(result, s3); if(result==s1) { puts("YES"); return 0; } result=s1; bigIntergerAdd(result, s3); if(result==s2) { puts("YES"); return 0; } result=s2; bigIntergerAdd(result, s1); if(result==s3) { puts("YES"); return 0; } puts("NO"); }
相关文章推荐
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- 高精度 I - Yet another A + B
- NodeMCU Builder, yet another NodeMCU IDE
- Yet Another Java Service Wrapper
- HDU 4596 Yet another end of the world(GCD)
- The 9th Zhejiang Provincial Collegiate Programming Contest->Problem :K-Yet Another Story of Rock-pap
- GYM 100488 A. Yet Another Goat in the Garden(计算几何)
- Yet Another Game of Stones
- 省赛热身赛之——Yet Another Story of Rock-paper-scissors
- Yet Another Median Task Gym - 100741G 二分中位数