高精度板( 无除法、减法 )
来源:互联网 发布:慢慢买数据怎么看 编辑:程序博客网 时间:2024/06/03 05:36
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<stack>#include<queue>#include<deque>#include<ctime>#include<climits>#include<map>#include<set>using namespace std;#define MAXM 205#define INF 0x7f7f7f7fconst int MAXN = 2000;struct BIGNUM{ int len, s[MAXN]; BIGNUM(){ len = 1 ; memset( s , 0 , sizeof(s)); } void get(){ char num[MAXN]; cin >> num; int n = strlen(num); for(len = 0; len < n; len++) s[len] = num[len] - '0'; return ; } void print(){ for(len --; len >= 0; len--) printf("%d", s[len]); return ; } BIGNUM operator = ( const char * num ){ len = strlen(num); for( int i = 0 ; i < len ; ++ i ) s[i] = num[ len - i - 1 ] - '0'; return * this; } BIGNUM operator = ( const int num ){ char a[MAXN]; sprintf( a , "%d" , num ); * this = a; return * this; } BIGNUM( const int num ){ * this = num; } BIGNUM( const char * num ){ * this = num; } BIGNUM operator + ( const BIGNUM & a ) const{ BIGNUM c; c.len = max( len , a.len ) + 1; for( int i = 0 , x = 0; i <c.len ; ++ i ){ c.s[i] = s[i] + a.s[i] + x; x = c.s[i] / 10; c.s[i] = c.s[i] % 10; } if( c.s[ c.len - 1 ] == 0 ) c.len --; return c; } BIGNUM operator += ( const BIGNUM & a ){ * this = *this + a; return * this; } BIGNUM operator * ( const BIGNUM & x ){ BIGNUM c; c.len = len + x.len; for( int i = 0 ; i < len ; ++ i ) for( int j = 0 ; j < x.len ; ++ j){ c.s[ i + j ] += s[i] * x.s[j]; c.s[ i + j + 1 ] += c.s[ i + j ] / 10; c.s[ i + j ] %= 10; } if( c.s[ c.len - 1 ] == 0 ) c.len --; return c; } BIGNUM operator *= ( const BIGNUM & a ){ * this = * this * a; return * this; } bool operator < ( const BIGNUM & x ) const { if( len != x.len ) return len < x.len; for( int i = len - 1 ; i >= 0 ; -- i ){ if( s[i] != x.s[i] ) return s[i] < x.s[i]; } return 0; } bool operator > ( const BIGNUM & x ) const { return x < * this; } bool operator <= ( const BIGNUM & x ) const { return !( x < *this ); } bool operator >= ( const BIGNUM & x ) const { return !( x > * this ); } bool operator == ( const BIGNUM & x ) const { return !( x < * this || * this < x ); } bool operator != ( const BIGNUM & x ) const { return x < * this || * this < x; } }a, b, f = INT_MAX, t; ostream & operator << ( ostream & out , const BIGNUM & x ){ for( int i = x.len - 1 ; i >= 0 ; -- i ) cout << x.s[i]; return out; } istream & operator >> ( istream & in , BIGNUM & x ){ char num[MAXN]; in >> num; x = num; return in; } int main(){ return 0; }
0 0
- 高精度板( 无除法、减法 )
- 高精度加法减法乘法除法
- 简单高精度入门总结(无除法)
- 大数加法 减法 乘法 除法 高精度四则运算
- 大数加法 减法 乘法 除法 高精度四则运算
- 高精度模板(减法)
- 整数高精度运算的库(加法,减法,乘法,除法,取模)
- 整数大数模拟 高精度加法 高精度减法 高精度乘法 高精度除法 c/c++ java
- 高精度除法(高精度除以高精度)
- 高精度(大整数减法)
- 大数减法 (高精度运算)
- (C语言)高精度减法
- uva10494 (高精度除法)
- 高精度减法
- 高精度减法
- 高精度减法
- 高精度减法
- 高精度减法
- #UWP#导航(navigation)的实现
- unix/linux ls命令的实现
- JZOJ 3637. 【COCI2013】linije
- Eclipse JSP/Servlet 环境搭建
- python系列整理列表
- 高精度板( 无除法、减法 )
- non-random numbers
- 使用HTML标签
- ArcGIS面简化工具的BUG
- 欧氏距离和余弦相似度
- Hibernate读取配置文件,创建sessionFactory的执行过程以及用工具类优化
- Android Fragment 真正的完全解析(下)
- HTML5+原生javascript 卡片扑克旋转展开效果demo
- springmvc整合mybatis框架源码 bootstrap html5 mysql oracle maven SSM