亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bignum.cpp

?? 處理大數 能夠處理負數 加減乘除優先順序
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
/**
 * Big integer class, optimized for decimal integers.
 * Stores and manipulates integers represented as byte arrays,
 * where each byte is a decimal digit. If you're looking for
 * robust, bug-free, efficient code, keep looking. This is a quick
 * and dirty hack. Some day I'll write a templatized BigInt, where
 * you will be able to select the base in which to store the 
 * number. When that day comes, most of this code will be thrown
 * away.
 *
 * BUGS:
 *      operator-(int) does not work.
 *
 *      BigInt doesn't play nice with long long. Either use int
 *      or string.
 *
 * INVARIANTS:
 *      - capacity is never smaller than 16
 *      - capacity is not the smallest it can be because every
 *         modifying member function first grows digits as much as
 *         it might ever need and then does its job.
 * FIELD TESTING:
 *      - Passed numerous problems on Valladolid, including
 *          107, 288, 324, 424, 465, 485, 495, 560, 619, 623, etc.
 *
 * COMPATIBILITY:
 *      - This class was written for the g++ compiler and uses some
 *          of the g++ extensions (like "long double" and the ">?="
 *          operator). If you want to compile this under Micro$oft's
 *          "compiler", I don't want to talk to you.
 *
 * LAST MODIFIED: October 5, 2005
 *
 * This file is part of my library of algorithms found here:
 *      http://www.palmcommander.com:8081/tools/
 * LICENSE:
 *      http://www.palmcommander.com:8081/tools/LICENSE.html
 * Copyright (c) 2002-2004
 * Contact author:
 *      igor at cs.ubc.ca
 **/

#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <sstream>
#include <math.h>

using namespace std;

#ifndef min
#define min(x,y) ((x) < (y) ? (x) : (y))
#endif

#ifndef max
#define max(x,y) ((x) > (y) ? (x) : (y))
#endif

class BigInt
{
    private:
        char *digits;
        int size;            // number of used bytes (digits)
        int capacity;        // size of digits
        int sign;            // -1, 0 or +1

    public:
        /** Creates a BigInt with initial value n and initial capacity cap **/
        BigInt( int n, int cap );

        /** Creates a BigInt with initial value n **/
        BigInt( int n );

        /** Creates a BigInt with initial value floor( d ) **/
        BigInt( long double d );

        /** Creates a BigInt with value 0 **/
        BigInt();

        /** Creates a BigInt by reading the value from a string **/
        BigInt( string s );

        /** Creates a BigInt by reading the value from a C string **/
        BigInt( const char s[] );

        /** Copy constructor **/
        BigInt( const BigInt &n );

        /** Assignment operators **/
        const BigInt &operator=( const BigInt &n );
        const BigInt &operator=( int n );

        /** Cleans up **/
        ~BigInt();

        /** Removes any leading zeros and adjusts the sign **/
        void normalize();

        /** Returns the sign of n: -1, 0 or 1 **/
        static int sig( int n );

        /** Returns the sign of n: -1, 0 or 1 **/
        static int sig( long double n );

        /** Returns the number of decimal digits **/
        inline int length() { return size; }

        /** Arithmetic **/
        BigInt operator++();
        BigInt operator++( int );
        BigInt operator--();
        BigInt operator--( int );
        BigInt operator-();
        BigInt operator+ ( int n    );
        BigInt operator+ ( BigInt n );
        BigInt&operator+=( int n    );
        BigInt&operator+=( BigInt n );
        BigInt operator- ( int n    );
        BigInt operator- ( BigInt n );
        BigInt&operator-=( int n    );
        BigInt&operator-=( BigInt n );
        BigInt operator* ( int n    );
        BigInt operator* ( BigInt n );
        void   operator*=( int n    );
        void   operator*=( BigInt n );
        BigInt operator/ ( int n    );
        BigInt operator/ ( BigInt n );
        void   operator/=( int n    );
        void   operator/=( BigInt n );
        int    operator% ( int n    );
        BigInt operator% ( BigInt n );
        void   operator%=( int n    );
        void   operator%=( BigInt n );
        int divide( int n );              // Divides storing quotient in *this and returning the remainder
        BigInt divide( BigInt n );        // Divides storing quotient in *this and returning the remainder
        BigInt operator* ( long double n ); // Multiplies by a double and truncates (always under-estimates!)
        void   operator*=( long double n ); // Multiplies by a double and truncates (always under-estimates!)

        /** Bitwise arithmetic **/
        BigInt operator<< ( int n    );
        void   operator<<=( int n    );
        BigInt operator>> ( int n    );   // Works differently for negative numbers
        void   operator>>=( int n    );   // Works differently for negative numbers
/*
        BigInt operator&  ( int n    );
        BigInt operator&  ( BigInt n );
        void   operator&= ( int n    );
        void   operator&= ( BigInt n );
        BigInt operator|  ( int n    );
        BigInt operator|  ( BigInt n );
        void   operator|= ( int n    );
        void   operator|= ( BigInt n );
        BigInt operator^  ( int n    );
        BigInt operator^  ( BigInt n );
        void   operator^= ( int n    );
        void   operator^= ( BigInt n );
        BigInt operator~();
*/
        /** Concatenation ;-) **/
        BigInt operator,( int n );
        BigInt operator,( BigInt n );

        /** Casting **/
        bool operator!();
        operator bool();
        //operator int();   //XXX: Don't do this!!! It takes precedence over operator+(int,BigInt)
        operator string();

        /** Comparison **/
        bool operator<( BigInt n );
        bool operator>( BigInt n );
        bool operator==( BigInt n );
        bool operator<=( BigInt n );
        bool operator>=( BigInt n );
        bool operator<( int n );
        bool operator>( int n );
        bool operator==( int n );
        bool operator<=( int n );
        bool operator>=( int n );
        int compare( BigInt n );

        /** Returns the lowest value as an integer (watch out for overflow) **/
        int toInt();

        /** Returns the value as a decimal string **/
        string toString();

        /** Outputs decimal value to stdout **/
        void print();

        /** Outputs the decimal value, with commas **/
        void printWithCommas( ostream &out );

    private:
        /** Expansion **/
        void grow();

    /** I/O Friends **/
    friend istream &operator>>( istream &in, BigInt &n );
    friend ostream &operator<<( ostream &out, BigInt n );

    /** Logarithms **/
    friend long double log2( BigInt x, long double epsilon );
    inline friend long double log( BigInt x, long double epsilon );
    inline friend long double log10( BigInt x, long double epsilon );
    inline friend long double lg( BigInt x, long double epsilon );
    inline friend long double ln( BigInt x, long double epsilon );
};

BigInt operator+( int m, BigInt &n )
{
    return n + m;
}

BigInt operator-( int m, BigInt &n )
{
    return -n + m;
}

BigInt operator*( int m, BigInt &n )
{
    return n * m;
}

BigInt operator/( int m, BigInt &n )
{
    return BigInt( m ) / n;
}

BigInt operator%( int m, BigInt &n )
{
    return BigInt( m ) % n;
}

/** Misc **/
inline bool isDigit( int c )
{
    return( c >= ( int )'0' && c <= ( int )'9' );
}

/** Input/Output **/
istream &operator>>( istream &in, BigInt &n )           // FIXME: see inside
{
    n.size = 0;
    n.sign = 1;
    int sign = 1;
    int c;
    while( ( c = in.peek() ) >= 0 &&
           ( c == ' ' || c == '\t' || c == '\r' || c == '\n' ) )
        in.get();
    if( c < 0 || ( c != ( int )'-' && !isDigit( c ) ) )
    {
        in >> c;                // XXX: force in.fail()
        return in;
    }
    if( c == ( int )'-' ) { sign = -1; in.get(); }

    // FIXME: Extremely inefficient! Use a string.
    while( ( c = in.peek() ) >= 0 && isDigit( c ) )
    {
        in.get();
        n *= 10;
        n += ( c - ( int )'0' );
    }
    n.sign = sign;      //XXX: assign n.sign directly after fixing the FIXME
    n.normalize();
    return in;
}

ostream &operator<<( ostream &out, BigInt n )       //FIXME: make more efficient
{
    return out << n.toString();
}

BigInt::BigInt( int n, int cap )
{
    cap = max( cap, ( int )sizeof( n ) * 8 );
    capacity = cap;
    sign = sig( n );
    n *= sign;
    digits = new char[cap];
    memset( digits, 0, cap );
    for( size = 0; n; size++ )
    {
        digits[size] = n % 10;
        n /= 10;
    }
}

BigInt::BigInt( int n )
{
    capacity = 1024;
    sign = sig( n );
    n *= sign;
    digits = new char[capacity];
    memset( digits, 0, capacity );
    size = 0;
    while( n )
    {
        digits[size++] = n % 10;
        n /= 10;
    }
}

BigInt::BigInt( long double d )
{
    capacity = 1024;
    sign = ( d < 0 ? -1 : d > 0 ? 1 : 0 );
    d *= sign;
    digits = new char[capacity];
    memset( digits, 0, capacity );
    size = 0;
    d = floor( d );
    while( d > 0 )
    {
        digits[size++] = 0 >? ( int )( ( d - floor( d / 10 ) * 10 ) + 0.5 ) <? 9;
        d = floor( d / 10 );
    }
}

BigInt::BigInt()
{
    capacity = 128;
    sign = 0;
    digits = new char[capacity];
    memset( digits, 0, capacity );
    size = 0;
}

BigInt::BigInt( string s )
{
    capacity = max( ( int )s.size(), 16 );
    sign = 0;
    digits = new char[capacity];
    memset( digits, 0, capacity );

    istringstream in( s );
    in >> ( *this );
}

BigInt::BigInt( const char s[] )
{
    capacity = max( ( int )strlen( s ), 16 );
    sign = 0;
    digits = new char[capacity];
    memset( digits, 0, capacity );

    istringstream in( s );
    in >> ( *this );
}

BigInt::BigInt( const BigInt &n )
{
    capacity = n.capacity;
    sign = n.sign;
    size = n.size;
    digits = new char[capacity];
    memcpy( digits, n.digits, capacity );
}

const BigInt &BigInt::operator=( const BigInt &n )
{
    if( &n != this )
    {
        if( capacity < n.size )
        {
            capacity = n.capacity;
            delete [] digits;
            digits = new char[capacity];
        }
        sign = n.sign;
        size = n.size;
        memcpy( digits, n.digits, size );
        memset( digits + size, 0, capacity - size );
    }
    return *this;
}

const BigInt &BigInt::operator=( int n )
{
    sign = sig( n );
    n *= sign;
    for( size = 0; n; size++ )
    {
        digits[size] = n % 10;
        n /= 10;
    }
    return *this;
}

BigInt::~BigInt()
{
    delete [] digits;
}

void BigInt::normalize()
{
    while( size && !digits[size-1] ) size--;
    if( !size ) sign = 0;
}

int BigInt::sig( int n )
{
    return( n > 0 ? 1 : ( n == 0 ? 0 : -1 ) );
}

int BigInt::sig( long double n )
{
    return( n > 0 ? 1 : ( n == 0 ? 0 : -1 ) );
}

int BigInt::toInt()
{
    int result = 0;
    for( int i = size - 1; i >= 0; i-- )
    {
        result *= 10;
        result += digits[i];
        if( result < 0 ) return sign * 0x7FFFFFFF;
    }
    return sign * result;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
天天色天天爱天天射综合| 精品av久久707| 一区二区三区欧美视频| 色哟哟精品一区| 亚洲一区二区三区三| 91精品国产一区二区三区香蕉| 蜜桃一区二区三区在线| 亚洲精品一区二区三区蜜桃下载 | 欧美日韩视频在线观看一区二区三区| 一二三四区精品视频| 日韩精品在线一区二区| 福利电影一区二区| 一区二区三区欧美激情| 欧美久久久久久久久久| 国产一区在线精品| 亚洲激情五月婷婷| 日韩一区二区三区四区| 懂色av一区二区三区蜜臀| 亚洲美女视频一区| 欧美一区二区三区精品| 成人av午夜电影| 免费在线看一区| 国产精品久久久久国产精品日日 | 777久久久精品| 国产成人精品亚洲午夜麻豆| 亚洲国产精品一区二区www在线 | 丝袜美腿高跟呻吟高潮一区| 欧美精品一区二区在线观看| 色偷偷久久一区二区三区| 人禽交欧美网站| 日韩一区欧美一区| 日韩亚洲欧美一区二区三区| aaa欧美日韩| 美女一区二区在线观看| 日韩美女久久久| 欧美成人a∨高清免费观看| 色综合久久88色综合天天6| 久久99热99| 亚洲午夜国产一区99re久久| 国产日韩精品一区二区浪潮av| 色欧美片视频在线观看| 国产精品亚洲人在线观看| 首页国产欧美久久| 亚洲日本乱码在线观看| 久久久影视传媒| 91精品在线麻豆| 一本色道综合亚洲| 成人一区二区三区| 九九精品一区二区| 日本欧美一区二区三区乱码| 亚洲欧美区自拍先锋| 久久久久久久久久久电影| 欧美一级艳片视频免费观看| 欧美三区免费完整视频在线观看| 99久久99久久综合| 国产suv精品一区二区883| 免费观看久久久4p| 日本中文在线一区| 亚洲第一综合色| 亚洲日本在线a| 中文字幕亚洲不卡| 中文字幕五月欧美| 国产精品久久久久久一区二区三区| 久久综合99re88久久爱| 精品国产sm最大网站免费看| 日韩一区二区在线看| 欧美日韩不卡视频| 欧美日韩亚洲高清一区二区| 欧美揉bbbbb揉bbbbb| 欧美视频在线观看一区| 欧美亚洲尤物久久| 欧美色综合网站| 欧美精品久久久久久久久老牛影院| 欧美少妇性性性| 91麻豆精品国产| 日韩免费一区二区三区在线播放| 日韩一区二区视频| 精品国产一区二区三区忘忧草| 日韩欧美国产麻豆| 精品99一区二区| 久久久久久久久久久久久夜| 国产婷婷精品av在线| 国产日韩精品一区| 国产精品久久午夜夜伦鲁鲁| 1024国产精品| 亚洲黄色性网站| 亚洲成人在线免费| 男人的天堂亚洲一区| 久久99深爱久久99精品| 国产成人一级电影| av电影天堂一区二区在线| 色欧美日韩亚洲| 制服丝袜亚洲精品中文字幕| 2欧美一区二区三区在线观看视频| 久久精品亚洲精品国产欧美| 综合久久久久久久| 婷婷成人综合网| 精品一区在线看| 99精品久久99久久久久| 欧洲一区二区av| 日韩一级二级三级精品视频| 国产亚洲欧美色| 亚洲人午夜精品天堂一二香蕉| 亚洲国产精品视频| 国内精品嫩模私拍在线| 色婷婷av一区二区三区之一色屋| 91麻豆精品国产91久久久更新时间| 欧美tk—视频vk| 亚洲精品写真福利| 蜜桃av噜噜一区| 9i在线看片成人免费| 777xxx欧美| 国产精品二区一区二区aⅴ污介绍| 亚洲影视在线观看| 国产一区二区三区精品欧美日韩一区二区三区 | 欧美亚洲丝袜传媒另类| 精品国产一区二区三区四区四| 1区2区3区国产精品| 视频在线观看国产精品| bt7086福利一区国产| 日韩三级视频中文字幕| 亚洲欧美日韩国产综合在线| 久久se精品一区精品二区| 在线视频你懂得一区二区三区| 精品久久五月天| 亚洲成年人网站在线观看| 成人国产在线观看| 精品乱人伦小说| 视频一区国产视频| 一本久久a久久精品亚洲| 久久久亚洲精品一区二区三区| 亚洲狠狠爱一区二区三区| 成人丝袜18视频在线观看| 日韩三级视频中文字幕| 一级日本不卡的影视| 成人久久视频在线观看| 精品成人在线观看| 三级欧美韩日大片在线看| 91丨九色丨蝌蚪富婆spa| 精品国偷自产国产一区| 视频一区免费在线观看| 在线观看成人小视频| 亚洲欧洲av一区二区三区久久| 狠狠色丁香婷综合久久| 欧美乱妇一区二区三区不卡视频| 亚洲乱码中文字幕综合| 成人性视频网站| 国产拍揄自揄精品视频麻豆| 麻豆免费看一区二区三区| 欧美日韩国产乱码电影| 亚洲一区二区三区美女| 日本久久电影网| 中文字幕一区二区日韩精品绯色| 国产精品911| 久久人人爽爽爽人久久久| 久久精品国产亚洲高清剧情介绍 | aaa亚洲精品| 中文字幕一区在线观看视频| 高清国产一区二区| 国产精品网站在线| 国产91富婆露脸刺激对白| 久久精品视频一区二区三区| 国产一区二区三区在线观看精品| 精品国产凹凸成av人网站| 精品无人区卡一卡二卡三乱码免费卡| 91精品国产91久久久久久一区二区| 亚洲不卡在线观看| 欧美精三区欧美精三区| 日韩不卡手机在线v区| 日韩视频永久免费| 国产自产高清不卡| 国产日韩视频一区二区三区| 国产精品1区2区3区在线观看| 国产欧美日韩三级| caoporn国产一区二区| 亚洲精品视频在线看| 欧美日韩一区二区在线观看| 五月天一区二区三区| 91精品在线麻豆| 国产精品一线二线三线| 国产精品国产三级国产普通话三级 | 精品国产免费人成在线观看| 国产专区综合网| 国产精品久久久久久福利一牛影视| 91在线云播放| 天堂影院一区二区| 精品国产乱码久久久久久牛牛 | 国产精品亚洲专一区二区三区| 国产精品素人一区二区| 色婷婷综合视频在线观看| 日韩影院在线观看| 久久精品人人做人人综合| 99久久久精品| 天使萌一区二区三区免费观看| 26uuu欧美| 色哟哟一区二区三区| 麻豆精品精品国产自在97香蕉 | 欧美手机在线视频| 久久精品国产第一区二区三区| 国产精品久久久久久久久免费樱桃 |