大数加法
来源:互联网 发布:字体识别软件 编辑:程序博客网 时间:2024/06/06 10:38
#include <iostream>#include <cstdio>#include <cstring>#include <sstream>#include <algorithm>#include <vector>#include <cmath>using namespace std;#define mem(a,n) memset(a,sizeof(a),n)typedef long long ll;const int mod=1e9+7;const int N=1e5+5;const int INF=0x3f3f3f3f;string a,b,c,d,ans;string add(string s1,string s2){ string s(""); int len1=s1.size()-1; int len2=s2.size()-1; int ca=0;///ca表示进位 while(len1!=-1&&len2!=-1) { int sum=ca+(s1[len1--]-'0')+(s2[len2--]-'0'); s+=((sum)%10+'0'); ca=sum/10; } while(len1!=-1)///若len1!=-1 { int sum=ca+(s1[len1--]-'0'); s+=((sum)%10+'0'); ca=sum/10; } while(len2!=-1)///若len2!=-1 { int sum=ca+(s2[len2--]-'0'); s+=((sum)%10+'0'); ca=sum/10; } if(ca) s+=(ca+'0'); reverse(s.begin(),s.end()); return s;}int main(){ int T; cin>>T; while(T--) { cin>>a>>b>>c>>d; ans=add(a,b); ans=add(ans,c); ans=add(ans,d); cout<<ans<<endl; } return 0;}
阅读全文
0 0
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 手机改成debug模式小工具及adb脚本问题
- 断点续传
- 无头单链表面试题(2)
- svn http://提示svn: Unrecognized URL scheme错误
- 【Aladdin Unity3D Shader编程】之四 贴图纹理
- 大数加法
- leetcode 669二叉搜索树
- Degree Sequence of Graph G(Hdu_oj 2454)
- HBase也疯狂
- Leetcode:240. Search a 2D Matrix II (week 11)
- PCL编程宝典-代码编译常见问题及解决办法
- postman使用
- jsp复习笔记
- PyPI使用国内源