亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
亚洲国产日日夜夜| 美女视频黄a大片欧美| 欧美一卡2卡3卡4卡| 99精品视频在线免费观看| 午夜一区二区三区在线观看| 国产午夜精品久久| 在线成人小视频| 色综合天天综合| 国产精品一线二线三线| 午夜不卡av免费| 亚洲视频在线一区| 久久久久九九视频| 日韩一卡二卡三卡国产欧美| 欧美自拍偷拍午夜视频| 不卡大黄网站免费看| 激情综合色综合久久综合| 天堂蜜桃一区二区三区 | 99精品视频在线播放观看| 经典三级一区二区| 日韩高清在线一区| 亚洲国产精品精华液网站| 国产精品午夜免费| 国产视频不卡一区| 久久亚洲欧美国产精品乐播| 日韩一级高清毛片| 制服.丝袜.亚洲.中文.综合| 欧美性三三影院| 色综合欧美在线| 成人午夜在线视频| 成人av中文字幕| 国产精品香蕉一区二区三区| 精品亚洲欧美一区| 九一九一国产精品| 国产在线乱码一区二区三区| 老鸭窝一区二区久久精品| 日韩va欧美va亚洲va久久| 无吗不卡中文字幕| 日韩av不卡在线观看| 日本亚洲视频在线| 男人的天堂久久精品| 免费观看一级特黄欧美大片| 亚洲高清免费在线| 偷窥国产亚洲免费视频| 亚洲国产毛片aaaaa无费看| 亚洲综合激情小说| 午夜久久久影院| 日本一道高清亚洲日美韩| 另类小说综合欧美亚洲| 国内精品国产三级国产a久久| 韩国精品一区二区| 成人黄色小视频| 91丨porny丨中文| 欧美亚洲日本国产| 欧美日韩国产区一| 日韩欧美一级二级| 久久久久久久网| 国产精品盗摄一区二区三区| 亚洲精品成人精品456| 午夜精品久久久| 日韩精品欧美精品| 国产揄拍国内精品对白| 成人国产精品免费观看视频| 色呦呦一区二区三区| 欧美日韩国产免费一区二区| 欧美一级电影网站| 久久久久免费观看| 亚洲人亚洲人成电影网站色| 亚洲午夜久久久久久久久久久 | 欧美日韩在线不卡| 欧美一区二区精品久久911| 久久久天堂av| 亚洲卡通动漫在线| 麻豆精品一区二区| www.激情成人| 91精品国模一区二区三区| 欧美精品一区在线观看| 亚洲欧美综合另类在线卡通| 亚洲二区在线观看| 国产精品2024| 欧美日韩免费高清一区色橹橹 | 免费国产亚洲视频| 成人高清视频在线| 8x8x8国产精品| 国产精品免费视频观看| 天天综合网 天天综合色| 国产一区 二区| 色综合久久99| ww亚洲ww在线观看国产| 亚洲精品日韩专区silk| 狠狠色狠狠色综合系列| 色婷婷综合在线| 久久久久国色av免费看影院| 亚洲午夜精品一区二区三区他趣| 国产福利一区二区三区视频在线| 欧美性生活大片视频| 久久精品视频在线看| 亚洲成人一二三| 波多野结衣中文字幕一区二区三区 | 国产米奇在线777精品观看| 91社区在线播放| 久久久一区二区三区捆绑**| 亚洲成在线观看| 99精品视频免费在线观看| 精品国产乱码久久久久久闺蜜| 亚洲欧美激情一区二区| 国产福利不卡视频| 日韩欧美在线影院| 亚洲mv大片欧洲mv大片精品| av激情亚洲男人天堂| 久久先锋影音av鲁色资源网| 亚洲aⅴ怡春院| 91首页免费视频| 欧美经典三级视频一区二区三区| 蜜桃视频一区二区三区| 欧美色精品天天在线观看视频| 国产精品每日更新| 国产电影一区二区三区| 日韩免费高清av| 日本成人在线一区| 欧美日韩国产高清一区二区| 亚洲女子a中天字幕| av成人免费在线观看| 国产亚洲视频系列| 国产精品一色哟哟哟| 欧美精品一区二区三区四区| 免费精品视频最新在线| 8v天堂国产在线一区二区| 亚洲一区二区四区蜜桃| 色综合久久久久综合体桃花网| 亚洲欧洲色图综合| 99久久精品国产精品久久| 中文字幕第一区二区| 福利一区二区在线| 国产欧美中文在线| 国产精品亚洲人在线观看| 精品国产麻豆免费人成网站| 国产最新精品免费| 久久久久99精品国产片| 极品少妇一区二区| 国产欧美一区二区三区鸳鸯浴| 国产精品一区二区91| 国产亚洲综合性久久久影院| 高清免费成人av| 国产精品久久久久久亚洲毛片| 99在线精品观看| 一区二区三区高清在线| 欧美日韩在线不卡| 日本欧美一区二区三区乱码| 欧美大白屁股肥臀xxxxxx| 久国产精品韩国三级视频| 亚洲精品在线免费观看视频| 国产精品538一区二区在线| 欧美激情一二三区| 色诱亚洲精品久久久久久| 亚洲va欧美va天堂v国产综合| 欧美一区二区在线看| 激情久久久久久久久久久久久久久久| 久久综合精品国产一区二区三区| 国产乱一区二区| 亚洲欧美在线视频观看| 91成人在线精品| 美女www一区二区| 国产视频一区不卡| 色综合色综合色综合| 日日摸夜夜添夜夜添国产精品| 日韩欧美一级特黄在线播放| 丰满白嫩尤物一区二区| 亚洲午夜精品网| xf在线a精品一区二区视频网站| 成人免费视频caoporn| 亚洲图片一区二区| 2023国产精华国产精品| 91一区一区三区| 蜜桃视频免费观看一区| 国产精品久久久久精k8 | 久久99精品国产麻豆婷婷洗澡| 久久久久久久综合| 在线亚洲一区观看| 国产在线精品视频| 亚洲午夜视频在线观看| 久久婷婷色综合| 欧美三级视频在线| 国产成人综合亚洲网站| 亚洲国产精品一区二区尤物区| 欧美精品一区视频| 欧美在线免费视屏| 风间由美一区二区av101| 婷婷国产在线综合| 日韩一区在线播放| 日韩你懂的在线播放| 97精品久久久午夜一区二区三区| 日韩1区2区日韩1区2区| 中文字幕一区二区三区四区不卡| 91麻豆精品国产综合久久久久久| 成av人片一区二区| 国产精一区二区三区| 日韩在线卡一卡二| 尤物av一区二区| 国产欧美一区二区精品久导航| 337p亚洲精品色噜噜狠狠|