该模板不是本人的,但是该是加了个头文件哒。不然在某个oj上编译错误。

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
struct bign{
int d[maxn], len;
void clean() { while (len > && !d[len - ]) len--; }
bign() { memset(d, , sizeof(d)); len = ; }
bign(int num) { *this = num; }
bign(char* num) { *this = num; }
bign operator = (const char* num){
memset(d, , sizeof(d)); len = strlen(num);
for (int i = ; i < len; i++) d[i] = num[len - - i] - '';
clean();
return *this;
}
bign operator = (int num){
char s[]; sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator + (const bign& b){
bign c = *this; int i;
for (i = ; i < b.len; i++){
c.d[i] += b.d[i];
if (c.d[i] > ) c.d[i] %= , c.d[i + ]++;
}
while (c.d[i] > ) c.d[i++] %= , c.d[i]++;
c.len = max(len, b.len);
if (c.d[i] && c.len <= i) c.len = i + ;
return c;
}
bign operator - (const bign& b){
bign c = *this; int i;
for (i = ; i < b.len; i++){
c.d[i] -= b.d[i];
if (c.d[i] < ) c.d[i] += , c.d[i + ]--;
}
while (c.d[i] < ) c.d[i++] += , c.d[i]--;
c.clean();
return c;
}
bign operator * (const bign& b)const{
int i, j; bign c; c.len = len + b.len;
for (j = ; j < b.len; j++) for (i = ; i < len; i++)
c.d[i + j] += d[i] * b.d[j];
for (i = ; i < c.len - ; i++)
c.d[i + ] += c.d[i] / , c.d[i] %= ;
c.clean();
return c;
}
bign operator / (const bign& b){
int i, j;
bign c = *this, a = ;
for (i = len - ; i >= ; i--)
{
a = a * + d[i];
for (j = ; j < ; j++) if (a < b*(j + )) break;
c.d[i] = j;
a = a - b*j;
}
c.clean();
return c;
}
bign operator % (const bign& b){
int i, j;
bign a = ;
for (i = len - ; i >= ; i--)
{
a = a * + d[i];
for (j = ; j < ; j++) if (a < b*(j + )) break;
a = a - b*j;
}
return a;
}
bign operator += (const bign& b){
*this = *this + b;
return *this;
}
bool operator <(const bign& b) const{
if (len != b.len) return len < b.len;
for (int i = len - ; i >= ; i--)
if (d[i] != b.d[i]) return d[i] < b.d[i];
return false;
}
bool operator >(const bign& b) const{ return b < *this; }
bool operator<=(const bign& b) const{ return !(b < *this); }
bool operator>=(const bign& b) const{ return !(*this < b); }
bool operator!=(const bign& b) const{ return b < *this || *this < b; }
bool operator==(const bign& b) const{ return !(b < *this) && !(b > *this); }
string str() const{
char s[maxn] = {};
for (int i = ; i < len; i++) s[len - - i] = d[i] + '';
return s;
}
}; istream& operator >> (istream& in, bign& x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream& out, const bign& x)
{
out << x.str();
return out;
}
int main()
{ }

高精度(x ,/, +, -, %)良心模板的更多相关文章

  1. C++高精度整数加减乘除模板

    其中高精度乘法通过了POJ2389,其他没有测过,不过应该是没有问题的. 其中高精度除法返回一对string,分别表示商和余数. 代码: #include <bits/stdc++.h> ...

  2. PAT A1024题解——高精度大数相加模板

    PAT:A1024 Palindromic Number A number that will be the same when it is written forwards or backwards ...

  3. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  4. POJ 2325 Persistent Numbers#贪心+高精度除法

    (- ̄▽ ̄)-* 这道题涉及高精度除法,模板如下: ]; ];//存储进行高精度除法的数据 bool bignum_div(int x) { ,num=; ;s[i];i++) { num=num*+ ...

  5. JDOJ 1790: 高精度A-B

    JDOJ 1790: 高精度A-B JDOJ传送门 洛谷 P2142 高精度减法 洛谷传送门 题目描述 高精度减法 输入格式 两个整数a,b(第二个可能比第一个大) 输出格式 结果(是负数要输出负号) ...

  6. Noip2016

    <这篇是以前的,不开新的了,借版面来换了个标题> 高二了 开学一周,每天被文化课作业碾压... 但是仍然阻挡不了想刷题的心情... 对付noip2016的几块:(有点少,以后补) 高精度( ...

  7. bc#29 做题笔记

    昨天的bc被坑惨了= = 本来能涨rating的大好机会又浪费了...大号已弃号 A:第一反应是高精度,结果模板找不到了= =,然后现学现卖拍了个java的BigInteger+快速幂,调了好半天不说 ...

  8. 【BZOJ1500】【NOI2005】维修数列(Splay)

    [BZOJ1500][NOI2005]维修数列(Splay) 题面 不想再看见这种毒瘤题,自己去BZOJ看 题解 Splay良心模板题 真的很简单 我一言不发 #include<iostream ...

  9. 【SHOI2012】魔法树(树链剖分,线段树)

    [SHOI2012]魔法树 题面 BZOJ上找不到这道题目 只有洛谷上有.. 所以粘贴洛谷的题面 题解 树链剖分之后直接维护线段树就可以了 树链剖分良心模板题 #include<iostream ...

随机推荐

  1. 关于setTimeout的的JS知识

    https://www.jianshu.com/p/3e482748369d?from=groupmessage

  2. epoll的高效实现原理

    epoll的高效实现原理 原文地址:http://blog.chinaunix.net/space.php?uid=26423908&do=blog&id=3058905 开发高性能网 ...

  3. .7-浅析webpack源码之WebpackOptionsDefaulter模块

    WebpackOptionsDefaulter模块 通过参数检测后,会根据单/多配置进行处理,本文基于单配置,所以会进行到如下代码: if (Array.isArray(options)) { com ...

  4. Docker版本变化和新版安装

    Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施.容器 ...

  5. jQuery 获取对象 根据属性、内容匹配, 还有表单元素匹配

    指定元素中包含 id 属性的, 如: $("span[id]") 代码如下: <span id="span1" name="S1"&g ...

  6. 乐字节-Java8新特性之Base64和重复注解与类型注解

    上一篇小乐给大家说了<乐字节-Java8新特性之Date API>,接下来小乐继续给大家说一说Java8新特性之Base64和重复注解与类型注解. 一.Base64 在Java 8中,内置 ...

  7. VisualSVN 手动记录访问操作日志

    一. VisualSVN 是一个可以免费使用的,SVN服务器端软件,基于 apache .可以实现 http https 多种SVN 发布功能. VisualSVN 默认是没有日志记录功能,需要手动打 ...

  8. 【Java并发编程】13、forkjoin

    http://www.infoq.com/cn/articles/fork-join-introduction http://www.importnew.com/14506.html Java7中的F ...

  9. Python3 系列之 环境配置篇

    以下所有操作是基于 Windows10 和 Python3.6 来进行的,其它平台和 python 版本请自行百度. 高效使用 Visual Studio Code 系列 环境安装 1.Python ...

  10. Python十讲 - 第一讲:从零开始学Python

    之后慢慢添加... Python语言的背景知识