• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            DraculaW

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              19 隨筆 :: 0 文章 :: 7 評論 :: 0 Trackbacks
            #ifndef _BIGNUM_HPP_
            #define _BIGNUM_HPP_

            #include <vector>
            #include <string>
            #include <iostream>

            using namespace std;

            class BigNum;

            BigNum operator+(const BigNum& lhs, const BigNum& rhs);

            ostream& operator<<(ostream& os, const BigNum& rhs);

            void Add(const BigNum& lhs, const BigNum& rhs, BigNum& res);

            class BigNum
            {
            public:
                BigNum(int n) : value(n){}
                BigNum(const string& s);
                friend BigNum operator+(const BigNum& lhs, const BigNum& rhs);
                friend ostream& operator<<(ostream& os, const BigNum& rhs);
                friend void Add(const BigNum& lhs, const BigNum& rhs, BigNum& res);
            private:
                vector<char> value;   
            };

            #endif

            #include "BigNum.hpp"

            BigNum::BigNum(const string& s):value(s.length())
            {
                int j = value.size();
                for(string::const_iterator it = s.begin(); it != s.end(); it++)
                {
                    j--;       
                    value[j] = *it;
                }
            }

            ostream& operator<<(ostream& os, const BigNum& rhs)
            {
                size_t i = rhs.value.size();
                bool zero = false;
                if( i == 1)
                    return os << rhs.value[0];

                if(rhs.value[ i - 1 ] == '0')
                    zero = true;
               
                while( i > 0 )
                {
                    i--;
                    while(zero == true)
                    {
                        i--;
                        if(rhs.value[i] != '0')
                            zero = false;
                    }
                    os << rhs.value[i];
                }
                return os;
            }

            void Add(const BigNum& lhs, const BigNum& rhs, BigNum& res)
            {
                int carry = 0;
                char c = 0;
                char tmp = 0;
                size_t i = 0;
                for( ; i < rhs.value.size(); i++)
                {
                    tmp = lhs.value[i] + rhs.value[i] + carry - '0';

                    if( tmp > '9' )
                    {
                        carry = 1;
                        tmp -= 10;
                    }
                    else
                    {
                        carry = 0;
                    }
                    res.value[i] = tmp;
                }

                while( carry != 0 && i < lhs.value.size() )
                {
                    tmp = lhs.value[i] + carry;
                    if( tmp > '9' )
                    {
                        carry = 1;
                        tmp = '0';
                    }
                    else
                    {
                        carry = 0;
                    }
                    res.value[i] = tmp;
                    i++;
                }

                if( carry > 0)
                    res.value[i] = '1';

            }

            BigNum operator+(const BigNum& lhs, const BigNum& rhs)
            {
                size_t lsize, rsize;
                lsize = lhs.value.size();
                       rsize = rhs.value.size();
                size_t n = lsize > rsize ? lsize : rsize;   
                BigNum res(n + 1);
                res.value[0] = '0';
               
                if( lsize > rsize )
                {
                         Add(lhs, rhs, res);
                }
                else
                {
                    Add(rhs, lhs, res);
                }
               
                return res;
            }

            //我自己實現的大數的加法的程序。。 終于驗證可以使用了 呵呵
            這個程序寫好了 也算可以了了我的心愿了的
            去年的某個時候 在杭州的UT斯達康面試 上機題就是這一道 我死活沒有憋出來,當時就很后悔 為什么不好好的看看論壇上的帖子 對上面的問題做做呢?那樣子的話 也許我就不會這么悲慘了,老是在哪里自怨自唉。
            總結起來 我其實是眼高手低,然后從來都被寵著沒有認清過自己。小學初中,老媽老師都說我數學學的還不錯,其實是有點小聰明,分數還是那么可憐的一點點;到高中,因 為學校比較一般,考的名次看起來很美,被假象迷惑了;大學,因為自己有點基礎,被給哥封為軟件最好,也有點沾沾自喜;到了這個公司,也許因為我身體的原 因,也有點面試時做題速度超快的原因,被經理說我程序不錯,還是沒有擺正自己的位子。
            受點挫折才好。嗯
            呵呵, 心態 , 心態才是一切。
            不要眼高手低
            posted on 2007-11-15 20:35 DraculaW 閱讀(201) 評論(0)  編輯 收藏 引用
            久久亚洲国产成人精品无码区| 久久精品国产只有精品66| 久久精品亚洲AV久久久无码| 久久婷婷色香五月综合激情| 亚洲色欲久久久综合网| 久久精品国产99国产精品澳门| 精品久久久久久99人妻| 久久精品国产久精国产一老狼| 7777久久亚洲中文字幕| 欧美日韩精品久久久久 | 久久天天躁夜夜躁狠狠| 久久亚洲2019中文字幕| 91麻豆精品国产91久久久久久| 性做久久久久久免费观看| 久久亚洲精品成人av无码网站| 国产欧美一区二区久久| 精品久久久一二三区| 狠狠色丁香久久婷婷综| 久久99九九国产免费看小说| 久久免费高清视频| 无码久久精品国产亚洲Av影片 | 中文无码久久精品| 久久久久综合中文字幕| 精品免费久久久久久久| 久久热这里只有精品在线观看| 久久久精品波多野结衣| 国产巨作麻豆欧美亚洲综合久久 | 一本久道久久综合狠狠爱| 久久久91人妻无码精品蜜桃HD| 久久99精品国产麻豆| 亚洲日本va中文字幕久久| 欧美一区二区久久精品| 最新久久免费视频| 一本色道久久88综合日韩精品| 狠狠人妻久久久久久综合| 亚洲国产精品久久久久婷婷软件| 亚洲狠狠婷婷综合久久蜜芽| 久久精品国产免费观看三人同眠| 欧美伊人久久大香线蕉综合| 久久国产亚洲精品| 亚洲精品无码久久久影院相关影片 |