實還在poj上面寫過乙個浮點數的乘法和加法運算,但個別題目會用到,所以不加進去了.
[cpp]view plain
copy
#include
#include
#include
#include
using
namespace
std;
#define maxn 1000
struct
hp
hp operator =(const
char
*num)
//字串賦值
hp operator =(int
num)
//int 賦值
hp(int
num)
hp(const
char
*num)
string str()const
//轉化成string
hp operator +(const
hp& b)
const
return
c;
} void
clean()
hp operator *(const
hp& b)
c.clean();
return
c;
} hp operator - (const
hp& b)
c.s[c.len++]=x;
} c.clean();
return
c;
} hp operator / (const
hp &b)
} c.len = len;
c.clean();
return
c;
} hp operator % (const
hp &b)
hp operator /= (const
hp &b)
hp operator %= (const
hp &b)
bool
operator < (
const
hp& b)
const
bool
operator > (
const
hp& b)
const
bool
operator <= (
const
hp& b)
bool
operator == (
const
hp& b)
bool
operator != (
const
hp &b)
hp operator += (const
hp& b)
bool
operator >= (
const
hp &b)
};
istream& operator >>(istream &in, hp& x)
ostream& operator <<(ostream &out, const
hp& x)
intmain()
當需要用long long 壓縮多位的時候
poj heritage (乙個long long 壓縮8位)
[cpp]view plain
copy
#include
#include
#include
#include
using
namespace
std;
#define maxn 4000
struct
hp
hp operator =(const
char
*num)
} if(tmp!=0)
s[k++]=tmp;
len=k;
return
*this
; }
hp operator =(int
num)
hp(int
num)
hp(const
char
*num)
string str()const
} long
long
tmp=s[len-1];
while
(tmp!=0)
if(res==
"") res=
"0";
return
res;
} hp operator +(const
hp& b)
const
return
c;
} void
clean()
hp operator *(const
hp& b)
c.clean();
return
c;
} hp operator - (const
hp& b)
c.s[c.len++]=x;
} c.clean();
return
c;
} void
output()
};
hp a[20];
intn;
intmain()
return
0;
}
浮點乘法 前導零只用clean清除,但是末尾需要轉化成string之後自行處理.del代表小數點第幾位之後
[cpp]view plain
copy
hp operator *(
const
hp& b)
c.clean();
return
c;
}
高精度類模板
更新提示 正文 這是乙個無符號整型高精度類的模板,以108 10 8 108壓位,支援加減乘法取模運算和算術左移右移運算,乘法用的是樸素實現方式,時間複雜度o n 2 o n 2 o n2 除法用的是倍增實現,時間複雜度o n log n o n log n o nlogn 支援直接輸入輸出。比較和...
高精度模板
include include include includeusing namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum bignum const int 將乙個int型別的變數轉化為大數 big...
高精度模板
include include include include include using namespace std const int maxn 1000 struct bign bign operator const char num 過載運算子 bign const char num 支援初...