高精度模板 - HZH's Blog - 自闭症

高精度模板

nbdhhzh posted @ 2014年8月20日 13:08 in 算法 with tags 模板 高精度 , 463 阅读

rt,自定义运算符写的,不过有点渣。。

#include<cstdio>
#include<cstring>
using namespace std;
struct num
{
    int fh,l,v[1001];
}x1,x2,san,ans,wu,xx;
int stack[3010],top,l,t,n,x;
char s1[1000010];
int max(int x,int y)
{
	if (x>y)return x;
	return y;
}
void clear(num &p)
{
    p.fh=p.l=0;
    memset(p.v,0,sizeof(p.v));
}
int bj(num a,num b)
{
    if (a.l!=b.l)return a.l>b.l;
    for (int i=a.l;i>=1;i++)
    {
        if (a.v[i]>b.v[i])return 1;
        if (a.v[i]<b.v[i])return 0;
    }
    return 1;
}
num operator /(num a,num b)
{
    num p;clear(p);p.fh=a.fh;p.l=max(a.l,b.l);
    for (int i=1;i<=p.l;i++)
        p.v[i]+=a.v[i]+b.v[i],p.v[i+1]=p.v[i]/10000,p.v[i]%=10000;
    while (p.v[p.l+1]>0)p.v[++p.l+1]=p.v[p.l]/10000,p.v[p.l]%=10000;
    return p;
}
num operator -(num a,num b)
{
    if (a.fh==-1&&b.fh==0){b.fh=-1;return a/b;}
    if (a.fh==0&&b.fh==-1){b.fh=0;return a/b;}
    if (!bj(a,b)){a.fh=-1-a.fh;b.fh=-1-b.fh;return b-a;}
    num p;clear(p);p.fh=a.fh;p.l=max(a.l,b.l);
    for (int i=1;i<=p.l;i++)
        p.v[i]+=a.v[i]-b.v[i],p.v[i+1]=(p.v[i]+10000)/10000-1,p.v[i]=(p.v[i]+10000)%10000;
    while (p.v[p.l]==0&&p.l>1)p.l--;
    return p;
}
num operator +(num a,num b)
{
    if (a.fh==-1&&b.fh==0){a.fh=0;return b-a;}
    if (a.fh==0&&b.fh==-1){b.fh=0;return a-b;}
    if (a.fh==b.fh)return a/b;
}
num operator *(num a,num b)
{
    num p;clear(p);p.fh=(a.fh+b.fh)%2;p.l=a.l+b.l-1;
    for (int i=1;i<=a.l;i++)
        for (int j=1;j<=b.l;j++)
            p.v[i+j-1]+=a.v[i]*b.v[j],p.v[i+j]+=p.v[i+j-1]/10000,p.v[i+j-1]%=10000;
    while (p.v[p.l+1]>0)p.v[++p.l+1]=p.v[p.l]/10000,p.v[p.l]%=10000;
    return p;
}
void write(num a)
{
    if (a.fh==-1)printf("-");
    printf("%d",a.v[a.l]);
    for (int i=a.l-1;i>=1;i--)
    {
        if (a.v[i]<1000)printf("0");
        if (a.v[i]<100)printf("0");
        if (a.v[i]<10)printf("0");
        if (a.v[i]<1)printf("0");
        printf("%d",a.v[i]);
    }
    printf("\n");
}
void read(num &a)
{
	int ln,kt,tot,i;
	scanf("%s",s1+1);
	ln=strlen(s1+1);kt=1;
	tot=1;a.l=1;
	if(s1[1]=='-')a.fh=-1,kt++;
	for(i=ln;i>=kt;i--)
	{
		a.v[a.l]+=(s1[i]-'0')*tot;
		tot=tot*10;
		if(tot==10000)tot=1,a.l++;
	}
	if(!a.v[a.l])a.l--;
}
Avatar_small
PNB Credit Card Onli 说:
2022年8月07日 06:40

Punjab National Bank is a well-known banking service not only in India but across the world due to their diversified service and financial assistance they provide to their customers, and they also provide credit card service to their eligible customers in order to help them run their lives smoothly and their payment process for this is smooth as well. PNB Credit Card Online Payment In this article, we will learn more about the different methods for payment through PNB Net Banking login and other modes. This new methods will help you through which you can make your Punjab National Bank credit card payment easily.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee