SDNU 1303.A+B(高精度) ......
来源:互联网 发布:淘宝的返利怎么领取 编辑:程序博客网 时间:2024/04/29 20:54
1303.A+B(高精度)
Description
求A+B
多组测试样例。两个正整数X,Y(0≤X,Y≤10^100)
输出结果
1 1
12345 54321
Sample Output
2
66666
题目已经说的很清楚是高精度了.......
下面代码
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char ads[105];char s1[105],s2[105];int additive(char* a,char* b){ memset(ads,0,sizeof(ads)); int len,len1,len2; int i; int ad[105]; len1=strlen(a); len2=strlen(b); if(len1==len2) { len=len1; } else if(len1>len2) { len=len1; for(i=len;i>=len-len2;i--) { b[i]=b[i-len+len2]; } for(i=len-len2-1;i>=0;i--) { b[i]='0'; } } else if(len1<len2) { len=len2; for(i=len;i>=len-len1;i--) { a[i]=a[i-len+len1]; } for(i=len-len1-1;i>=0;i--) { a[i]='0'; } } int t=0; for(i=len-1;i>=0;i--) { ad[i]=(a[i]-'0')+(b[i]-'0')+t; t=0; if(ad[i]>=10) { t++; ad[i]=ad[i]-10; ads[i]=ad[i]+'0'; } else { ads[i]=ad[i]+'0'; } } if(t==1) { for(i=len;i>=0;i--) { ads[i]=ads[i-1]; } ads[0]='1'; } return 0;}int main(){ while(scanf("%s",s1)!=EOF) { scanf("%s",s2); additive(s1,s2); cout<<ads<<endl; } return 0;}
0 0
- SDNU 1303.A+B(高精度) ......
- SDNU 1303 高精度(A+B)
- sdnu oj 1056 A ^ B Problem
- 1381 a*b 高精度
- 高精度大数A+B
- A+B Problem 高精度
- A + B高精度
- a+b(高精度)
- 【高精度算法】A*B
- 【高精度算法】A+B
- 高精度 A*B Problem
- 高精度 A+B Problem
- 高精度 A-B Problem
- a+b高精度
- A+B高精度问题
- 【高精度算法】A+B
- a+b 高精度
- 高精度求A+B
- Shell 变量及函数讲解 [2]
- 让我们来谈谈分工
- 数据结构(4)—— 栈、队列代码重构实现
- processing基础1
- Linux 字体颜色设置
- SDNU 1303.A+B(高精度) ......
- Dijkstra算法的纯java实现
- 如何在一台机器上配置多个git的rsa
- 手机网页取消长按事件
- Android-ViewPagerIndicator简单集成
- KVM 安装
- Hibernate缓存机制
- javascript读书笔记(二)
- Android自适应国际化语言