int main()
{
string a, b; //two strings to store the input
int index; //the variable to mark the position
int* first = new int[100]; //pointer to an array storing the first number
int* second = new int[100]; //pointer to an array storing the second number
int* total = new int[101]; //pointer to an array storing the result
//initialize the arrays
for (int n=0; n<100; n++)
{
first[n] = 0;
second[n] = 0;
}
//prompt the user to input the first number
cout<<"Please input the first number:"<<endl;
cin>>a;
//the length of string a
int lengthA = a.length();
//prompt the user to input the first number
cout<<"Please input the second number:"<<endl;
cin>>b;
//the length of string b
int lengthB = b.length();
//convert every three characters in string a to numbers and store them in array
for(int i=0; i<(lengthA/3); i++)
{
first[i] = atoi(a.substr((lengthA-3*i-3),3).c_str());
}
if(lengthA%3!=0)
{
first[lengthA/3] = atoi(a.substr(0,lengthA%3).c_str());
}
//convert every three characters in string b to numbers and store them in array
for (int j=0; j<(lengthB/3); j++)
{
second[j] = atoi(b.substr((lengthB-3*j-3),3).c_str());
}
if(lengthB%3!=0)
{
second[lengthB/3] = atoi((b.substr(0,lengthB%3).c_str()));
}
//add the numbers in two arrays and store them in total
total = addNumber(first, second);
cout<<endl;
//find out the index of the first element of the result
for (int k=100; k>=0; k--)
{
if(total[k]!=0)
{
index = k;
break;
}
}
//Print out the final result
cout<<"The result is: "<<endl;
cout<<total[index];
for (int l=index-1; l>=0; l--)
{
if(total[l]<100 && total[l]>=10)
{
cout<<"0"<<total[l];
}
else if(total[l]<10)
{
cout<<"00"<<total[l];
}
else
{
cout<<total[l];
}
}
cout<<endl;
return 0;
}
//add every element in two arrays
int* addNumber(int* first, int* second)
{
int* total = new int[101];
for (int i=0; i<101; i++)
{
total[i] = 0;
}