您的位置:首页 > 其它

【模板(们)】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;
}


高精度加减
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: