///
///
Base class, abstract class, defining common methods
///
Abstract
Class bigcalculate
{
Public abstract string evaluate (string num1, string num2 );
// Reverse the numerical order
Protected string invertorder (string Str)
{
Char [] chtemp = new char [Str. Length];
For (INT I = 0; I <Str. length; I ++)
{
Chtemp [I] = STR [Str. Length-i-1];
}
Return new string (chtemp. toarray ());
}
// Exchange numbers
Protected void changenum (ref string num1, ref string num2)
{
String strtemp = num1;
Num1 = num2;
Num2 = strtemp;
}
// Obtain a large number
Protected string max (string num1, string num2)
{
If (num1.length> num2.length)
{
Return num1;
}
Else if (num1.length = num2.length)
{
For (INT I = num1.length-1; I> = 0; I --)
{
If (num1 [I]. compareto (num2 [I]) <0)
{
Return num2;
}
}
Return num1;
}
Return num2;
}
}
--------------------------------------------------------------------------
class
bigadd: bigcalculate
{< br>
Public override string evaluate (string num1, string num2)
{< br>
// obtain a large number of digits
int Len = num1.length> num2.length? Num1.length:
num2.length;
// Add 0 to the decimal digit
string tempnum1 = new string ('0 ', len-num1.length) + num1;
string tempnum2 = new string ('0', len-num2.length) + num2;
int flag = 0; // carry character
List Lich = new list (); // store the number after calculation
for (INT I = len-1; I >=0; I --)
{< br>
Lich. add (char) (tempnum1 [I] + tempnum2 [I] + flag-'0');
flag = (Lich [Lich. count-1]-'0')/10;
Lich [Lich. count-1] = (char) (Lich [Lich. count-1]-'0') % 10) +
'0');
}
// If the input character is not 0 after the computation, and the highest bit carry, add another digit.
If (flag> 0)
{
Lich. Add (char) (flag + '0 '));
}
Return invertorder (new string (lich. toarray ()));
}
}