大数相加
来源:互联网 发布:js给select标签负值 编辑:程序博客网 时间:2024/04/30 20:44
#include<cstdio>#include<cstring>#include<iostream>using namespace std;struct bigInteger{ int size; int digit[1000]; void init() { memset(digit,0,sizeof(digit)); size=0; } void set(char str[]) { init(); int L=strlen(str); for(int i=L-1,j=0,t=0,c=1;i>=0;i--) { t+=(str[i]-'0')*c; c=c*10; j++; if(j==4||i==0) { digit[size++]=t; j=0; c=1; t=0; } } } void output() { for(int i=size-1;i>=0;i--) { if(i!=size-1) printf("%4d",digit[i]); else printf("%d",digit[i]); } printf("\n"); } bigInteger operator+(const bigInteger &A)const { bigInteger ret; ret.init(); int carry=0; for(int i=0;i<size||i<A.size;i++) { int tmp=A.digit[i]+digit[i]+carry; carry=tmp/10000; tmp%=10000; ret.digit[ret.size++]=tmp; } if(carry!=0) ret.digit[ret.size++]=carry; return ret; }}a,b,c;char str1[1002],str2[1002];int main(){ while(scanf("%s%s",str1,str2)!=EOF) { a.set(str1); b.set(str2); c=a+b; c.output(); } return 0;}
0 0
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 区间dp基础(石子归并,括号匹配,整数划分。。。)
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake(dp、BIT)
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemF:80ers' Memory
- C++模板简单学习
- 线上使用阿里Druid连接池首次连接MySQL异常问题
- 大数相加
- Git分支管理策略
- HTTP Live Streaming for iPhone/iPad(HLS流媒体服务器)
- The 6th Zhejiang Provincial Collegiate Programming Contest->Problem I:A Stack or A Queue?
- [1005]: Number Sequence
- Android中不能使用HttpClient了
- linux的chmod、chown详解
- 最大子数组问题
- 黑盒测试