P1601 A+B Problem(高精)
来源:互联网 发布:递归算法理解 编辑:程序博客网 时间:2024/05/23 19:41
高精度加法。
太久没写了,竟以为=也需要重载,然而相同的两个数据类型,等于号是不需要重载的。
令外写错了两个地方。//
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int MAXN = 1000;inline int get(){char c;while((c = getchar()) < '0' || c > '9');int cnt = c - '0';while((c = getchar()) >= '0' && c <= '9') cnt = cnt * 10 + c - '0';return cnt;}char s1[MAXN],s2[MAXN];struct data{int a[MAXN],len;data(){memset(a,0,sizeof(a));} data operator + (const data& b){data c;c.len = max(len,b.len);for(int i = 1; i <= c.len; i++){ //len -> c.lenc.a[i] += a[i] + b.a[i]; // c.a[i] = a[i] + b.a[i]if(c.a[i] >= 10){c.a[i] -= 10;c.a[i+1]++;}}if(c.a[c.len+1] != 0) c.len++;return c;}}a,b;int main(){/*#ifdef lwy#elsefreopen(".in","r",stdin);freopen(".out","w",stdout);#endif*/scanf("%s %s",s1,s2);a.len = strlen(s1);b.len = strlen(s2);for(int i = a.len - 1; i >= 0; i--){a.a[a.len - i] = s1[i] - '0';}for(int i = b.len - 1; i >= 0; i--){b.a[b.len - i] = s2[i] - '0';}a = a + b;for(int i = a.len; i >= 1; i--){printf("%d",a.a[i]);}return 0;}
阅读全文
0 0
- P1601 A+B Problem(高精)
- P1601 A+B Problem(高精)
- 高精度加法 洛谷 P1601 A+B Problem(高精)
- 洛谷 P1601 A+B Problem(高精)
- A+B Problem(高精)
- A+B Problem(高精)
- 高精度——A+B Problem(高精)
- 【洛谷 1601】A+B Problem(高精)
- [P1601]高精加法[压位]
- 【给将来学神的算法详解--高精】(3)A+B Problem
- 洛谷 1601 A+B Problem(高精)(The Last Problem In MY Winter Holiday,the Thirtieth)
- A+B Problem(V)
- A+B Problem(水)
- (1)A+B Problem
- A+B Problem(V)
- A+B Problem(V)
- A+B Problem(高精加)
- A+B Problem(V)
- 定期删除elasticsearch集群10天以上的索引
- 减肥这事是个大事
- select标签加超链接的三种实现方法
- python多线程与进程
- 用swing 实现Icon 图标
- P1601 A+B Problem(高精)
- Java 注解一
- CodeForces
- 出场、入场动画大全,基于NineOldAndroids轻松实现动画效果
- MySQL ALTER命令(修改数据表相关)
- EA&UML日拱一卒-状态图::迁移
- 设计模式笔记之适配器模式
- Ubuntu常用命令大全
- PATH记录