【模板(们)】noip前热身练习(更新中...)
2017-11-06 21:25
260 查看
分块+莫队
高精度加减
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=100000+5; struct Type{ int a ,len; }; void read(Type &res){ char ch=0; res.a[0]=1,res.len=0; while(ch<'0'||ch>'9'){if(ch=='-')res.a[0]=-1;ch=getchar();} while(ch>='0'&&ch<='9'){res.a[++res.len]=ch-'0';ch=getchar();} for(int i=1;i<=res.len/2;i++) swap(res.a[i],res.a[res.len-i+1]); } void print(const Type &pr){ if(pr.a[0]==-1) printf("-"); for(int i=pr.len;i>=1;i--) printf("%d",pr.a[i]); } Type operator +(Type _a,Type _b){ Type _c; _c.len=max(_a.len,_b.len); int tmp=0; for(int i=1;i<=min(_a.len,_b.len);i++){ tmp=_a.a[i]+_b.a[i]+tmp; _c.a[i]=tmp%10; tmp/=10; } for(int i=min(_a.len,_b.len)+1;i<=_c.len;i++){ tmp=_a.len>_b.len?_a.a[i]+tmp:_b.a[i]+tmp; _c.a[i]=tmp%10; tmp/=10; } if(tmp) _c.a[++_c.len]=tmp; return _c; } Type operator -(Type _a,Type _b){ Type _c; _c.len=_a.len; for(int i=1;i<=_b.len;i++){ _c.a[i]=_a.a[i]-_b.a[i]; if(_c.a[i]<0) _c.a[i]+=10,_a.a[i+1]--; } for(int i=_b.len+1;i<=_a.len;i++) _c.a[i]=_a.a[i]; while(_c.a[_c.len]==0) _c.len--; return _c; } Type a,b; int main(){ read(a),read(b); print(a-b); return 0; }
高精度加减
相关文章推荐
- codevs 1080~1082 线段树练习系列(模板)
- 面向对象程序设计上机练习二(函数模板)
- 【NOIP模板】KMP
- 【模板练习——AC自动机】Keywords Search HDU - 2222
- 【NOIP模板】 trie树
- 高精度简单练习 【模板】
- UVa 10474Where is the Marble STL 模板练习
- C++ 模板练习摘要
- NOIP复赛复习(三)文件读写与数论模板
- 2018年全国多校算法寒假训练营练习比赛(第三场)---E---题(大数阶乘(模板题)c++/java/py)
- 小白算法练习 数位dp模板
- 线段树练习 3&P3372 【模板】线段树 1
- SDUT 2143 图结构练习——最短路径 SPFA模板,方便以后用。。
- sdut 面向对象程序设计上机练习二(函数模板)
- c++ 模板练习2
- 【函数模板】面向对象程序设计上机练习二(函数模板)
- noip2008 真题练习 2017.2.25
- NOIP 信息学 奥赛 考纲 考点 模板 裸题 水题
- 面向对象程序设计上机练习二(函数模板)
- NOIP前 基础动态规划模板