高精度运算类 bign 和常用运算符重载


#include <stdio.h>
#include <string.h>
#include <string>
using std::string;
const int maxn = 1000;
struct bign
{
    int len,s[maxn];
    bign(){ memset(s, 0, sizeof(s));len =1;}
    
    //重新定义赋值运算符
    bign operator =(const char* num)
    {
        len = strlen(num);
        for(int i =0;i<len;i++) s[i] = num[len-i-1]-'0';
        return *this;
    }
    
    bign operator =(int num)
    {
        char s[maxn];
        sprintf(s, "%d",num);
        *this =s;
        return *this;
    }
    
    bign (int num){ *this =num;}
    bign (const char* num){*this = num;}
    
    string str() const
    {
        string res = "";
        for(int i =0;i<len;i++) res= (char)(s[i]+'0')+res;
        if(res == "") res ="0";
        return res;
    }
};
//重新定义》》和《《运算符
//重载bign的常用运算符 +-*/ 》 《 《= 》= != ==

 

posted @ 2015-07-07 15:20  微博和csdn还有你  阅读(340)  评论(0编辑  收藏  举报