高精度(加法)
来源:互联网 发布:python黑帽子中文 编辑:程序博客网 时间:2024/05/29 19:49
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=510;
char a[maxn],b[maxn];
int x[maxn],y[maxn],z[maxn];
int main(){
memset(z,0,sizeof(z));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
scanf("%s%s",a,b);
int l1=strlen(a),l2=strlen(b);
for(int i=1;i<=l1;i++) x[i]=a[l1-i]-'0';
//for(int i=1;i<=l1;i++) cout<<x[i]<<' ';
//cout<<endl;
for(int i=1;i<=l2;i++) y[i]=b[l2-i]-'0';
//for(int i=1;i<=l2;i++) cout<<y[i]<<' ';
//cout<<endl;
int l3=max(l1,l2),cur=0;
for(int i=1;i<=l3;i++){
z[i]+=x[i]+y[i];
if(z[i]>=10){
z[i+1]+=(z[i]/10);
z[i]%=10;
}
}
while(z[l3+1]){
++l3;
}
for(int i=l3;i>=1;i--) cout<<z[i];
cout<<endl;
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=510;
char a[maxn],b[maxn];
int x[maxn],y[maxn],z[maxn];
int main(){
memset(z,0,sizeof(z));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
scanf("%s%s",a,b);
int l1=strlen(a),l2=strlen(b);
for(int i=1;i<=l1;i++) x[i]=a[l1-i]-'0';
//for(int i=1;i<=l1;i++) cout<<x[i]<<' ';
//cout<<endl;
for(int i=1;i<=l2;i++) y[i]=b[l2-i]-'0';
//for(int i=1;i<=l2;i++) cout<<y[i]<<' ';
//cout<<endl;
int l3=max(l1,l2),cur=0;
for(int i=1;i<=l3;i++){
z[i]+=x[i]+y[i];
if(z[i]>=10){
z[i+1]+=(z[i]/10);
z[i]%=10;
}
}
while(z[l3+1]){
++l3;
}
for(int i=l3;i>=1;i--) cout<<z[i];
cout<<endl;
return 0;
}
阅读全文
0 0
- 大数(高精度)加法
- 二进制(高精度加法)
- 高精度加法(c++)
- 高精度(加法)
- 高精度整数加法(大整数加法)
- 蓝桥杯BASIC29 高精度加法(数组 高精度)
- 高精度计算(附高精度加法程序)
- 高精度(大整数加法)
- poj_2506 Tiling(高精度加法)
- 蓝桥杯--高精度加法(vip)
- 高精度(乘法和加法)
- (C语言)高精度加法
- 高精度的加法(c++)
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度 加法
- 编译caffe出现错误 opencv
- bzoj 4810 [Ynoi2017]由乃的玉米田(莫队+bitset)
- 利用异或进行密码加密
- hibernate.cfg.xml
- day08笔记
- 高精度(加法)
- js进行图片相关操作
- linux 软件开发小工具
- 1、面向对象思想 2、类与对象的关系 3、局部变量和成员变量的关系 4、封装思想 5、private,this关键字 6、随机点名器
- day09笔记
- ServletRequest中getReader()和getInputStream()只能调用一次的解决办法
- 二叉树的下一个节点
- LintCode 关于动态规划问题的总结
- 从K近邻算法、距离度量谈到KD树、SIFT+BBF算法