直客sup源码免授权(sup直客系统破解版)
本文目录一览:
求大数运算C++源代码,有重+ -*/ >比较
#ifndef NODE
#define NODE
class Node
{
public:
char cBit;
Node* pNext;
Node(char c):cBit(c)
{
pNext=0;
}
Node operator=(const Node node)
{
this-pNext=node.pNext;
this-cBit=node.cBit;
return *this;
}
};
#endif
/**************************/
#ifndef STACK
#define STACK
#include "node.h"
#include "iostream.h"
#include "process.h"
class stack
{
public:
stack()
{
pTop=NULL;
nSize=0;
}
explicit stack(char);
stack(stack);
stack operator=(stack);
bool push(char);
char pop();
char Iter(int );
bool empty(){
return nSize=0;
}
int GetSize() const
{
return nSize;
}
private:
Node* pTop;
int nSize;
};
stack::stack(char init):nSize(1)
{
pTop=NULL;
Node* pNewNode=new Node(init);
if (pNewNode)
{
pTop=pNewNode;
pTop-pNext=NULL;
}
else
{
cerr"Memory Allocation Failed!\n";
exit(1);
}
}
stack::stack(stack sStack)
{
pTop=NULL;
nSize=0;
int nIndex=sStack.GetSize();
stack* temp=new stack;
if(temp)
while(nIndex)
{
temp-push(sStack.Iter(nIndex));
}
else
{
cerr"Memory Allocation Error!\n";
exit(0);
}
while (!temp-empty())
{
this-push(temp-pop());
}
delete temp;
temp=NULL;
}
stack stack::operator =(stack sStack)
{
int nIndex=sStack.GetSize();
stack* temp=new stack;
if(temp)
while(nIndex)
{
temp-push(sStack.Iter(nIndex));
}
else
{
cerr"Memory Allocation Error!\n";
exit(0);
}
while (!temp-empty())
{
this-push(temp-pop());
}
delete temp;
temp=NULL;
return *this;
}
bool stack::push(char cNum)
{
Node* pNewNode=new Node(cNum);
if (pNewNode)
{
pNewNode-pNext=pTop;
pTop=pNewNode;
nSize++;
return true;
}
else
return false;
}
char stack::pop()
{
if (nSize0)
{
char cTop=pTop-cBit;
Node* pTempTop=pTop;
pTop=pTop-pNext;
nSize--;
delete pTempTop;
pTempTop=NULL;
return cTop;
}
else return '\0';
}
char stack::Iter(int nIndex)
{
if (nIndex=0||nIndexnSize)
return '\0';
Node* pFromTop=pTop;
for (int i=nSize-nIndex;i0;i--)
{
pFromTop=pFromTop-pNext;
}
nIndex--;
return pFromTop-cBit;
}
#endif
/*********************************/
#ifndef SUPNUM
#define SUPNUM
#include "Stack.h"
#include "conio.h"
unsigned int pow(unsigned int,int);
class SupNum
{
public:
SupNum();
explicit SupNum(char);
SupNum(SupNum);
SupNum operator+(SupNum );
SupNum operator*(SupNum );
SupNum operator+=(SupNum Right_op)
{
*this=*this+Right_op;
return *this;
}
SupNum operator*=(SupNum Right_op)
{
*this=*this*Right_op;
return *this;
}
SupNum exp(int);
int GetStackSize(){
return pNumStr-GetSize();
}
stack* GetStack(){
return pNumStr;
}
friend ostream operator(ostream ,SupNum);
friend istream operator(istream ,SupNum);
private:
stack* pNumStr;
SupNum operator*(int);
};
//////////////////////////////
SupNum::SupNum()
{
pNumStr=new stack;
if (!pNumStr)
{
cerr"Memory Allocation Failed!\n";
exit(1);
}
}
SupNum::SupNum(char init)
{
pNumStr=new stack(init);
if (!pNumStr)
{
cerr"Memory Allocation Failed!\n";
exit(1);
}
}
SupNum::SupNum(SupNum Sup)
{
pNumStr=new stack;
if (!pNumStr)
{
cerr"Memory Allocation Failed!\n";
exit(1);
}
*pNumStr=*(Sup.GetStack());
}
SupNum SupNum::operator *(int iMulti)
{
SupNum temp;
for (int i=0;iiMulti;i++) {
temp+=*this;
}
return temp;
}
ostream operator(ostream os,SupNum sup )
{
stack temp;
int index=sup.GetStackSize();
while(index)
temp.push(sup.GetStack()-Iter(index));
while (!temp.empty())
{
ostemp.pop();
}
return os;
}
istream operator (istream is,SupNum sup)
{
char bit='0';
while (1)
{
bit=getche();
if(bit!=' ')
break;
}
while (1)
{
if(bit='0'bit='9')
sup.GetStack()-push(bit);
bit=getche();
if(bit==' '||bit=='\r')
break;
}
if(bit=='\r')
coutendl;
return is;
}
SupNum SupNum::operator +(SupNum Right_op)
{
int check=1;
if(Right_op.GetStack()-Iter(check)=='0')
return *this;
int tag=0;
char sum='\0';
SupNum thisSup=*this;
SupNum RightSup=Right_op;
int Right_op_size=RightSup.GetStackSize();
SupNum* pTempresult=new SupNum;
if(pTempresult==NULL) exit(1);
SupNum pResult;
while (!thisSup.GetStack()-empty()!RightSup.GetStack()-empty())
{
sum=thisSup.GetStack()-pop()+RightSup.GetStack()-pop()-'0';
if (sum+tag'9')
{
pTempresult-GetStack()-push(char(sum+tag-10));
tag=1;
}
else
{
pTempresult-GetStack()-push(char(sum+tag));
tag=0;
}
}//the first
SupNum *pBigger=(this-GetStack()-GetSize()Right_op_size?thisSup:RightSup);
if(tag==0)
while(!pBigger-GetStack()-empty())
pTempresult-GetStack()-push(pBigger-GetStack()-pop());
else
if(thisSup.GetStackSize()==Right_op_size)
pTempresult-GetStack()-push('1');
else
{
while (!pBigger-GetStack()-empty())
{
sum=pBigger-GetStack()-pop();
if (sum+tag'9')
{
pTempresult-GetStack()-push(char(sum+tag-10));
tag=1;
}
else
{
pTempresult-GetStack()-push(char(sum+tag));
tag=0;
}
}//while
if(tag)
pTempresult-GetStack()-push('1');
}//else
while (!pTempresult-GetStack()-empty())
pResult.GetStack()-push(pTempresult-GetStack()-pop());
delete pTempresult;
return pResult;
}
SupNum SupNum::operator*(SupNum Right_op)
{
int check=1;
if(Right_op.GetStack()-Iter(check)=='0')
return SupNum('0');
SupNum supResult;
int index=Right_op.GetStackSize();
int iRopSize=index;
int* pNumStr=new int[iRopSize];
for (int i=0;iiRopSize;i++)
pNumStr[i]=(Right_op.GetStack()-Iter(index)-'0')*pow(10,i);
for (int k=0;kiRopSize;k++)
supResult+=*this*(pNumStr[k]);
return supResult;
}
SupNum SupNum::exp(int nIndex)
{
SupNum temp=*this;
for(int i=1;inIndex;i++)
temp=temp*(*this);
return temp;
}
unsigned int pow(unsigned int x,int e)
{
int iResult=1;
for (int i=0;ie;i++)
iResult*=x;
return iResult;
}
#endif
/*****************************/
#include "SupNum.h"
int main()
{
SupNum num_1,num_2;
cout"输入两个数:"endl;
cinnum_1num_2;
SupNum num3;
cout"num_1="num_1endl;
cout"num_2="num_2endl;
num3=num_1.exp(10);
coutnum_1"直客sup源码免授权的十次方为"num3endl;
cout"按任意键继续...";
getch();
return 0;
}