# include <iostream.h>
# include <fstream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
int main( )
{
clrscr( );
fstream File("CP-26.txt",ios::in|ios::nocreate);
if(!File)
{
cout<<"\n Unable to open the input file."<<endl;
cout<<"\n Press any key to exit.";
getch( );
exit(EXIT_FAILURE);
}
char Data[60]={NULL};
char Temp[60]={NULL};
char Operator[60]={NULL};
char Result[60]={NULL};
File.getline(Data,50);
int test_cases=atoi(Data);
for(int count=1;count<=test_cases;count++)
{
strset(Data,NULL);
File.getline(Data,50);
strrev(Data);
do
{
strset(Temp,NULL);
strset(Result,NULL);
strset(Operator,NULL);
File.getline(Operator,50);
if(strcmp(Operator,"=")==0)
break;
File.getline(Temp,50);
strrev(Temp);
while(strlen(Temp)<strlen(Data))
strcat(Temp,"0");
while(strlen(Data)<strlen(Temp))
strcat(Data,"0");
int length=strlen(Data);
if(strcmp(Operator,"+")==0)
{
int carry=0;
int sum=0;
int digit_1=0;
int digit_2=0;
char Sum[5]={NULL};
for(int i=0;i<length;i++)
{
digit_1=(int(Data[i])-48);
digit_2=(int(Temp[i])-48);
sum=(digit_1+digit_2+carry);
if(sum>9)
{
sum%=10;
carry=1;
}
else
carry=0;
itoa(sum,Sum,10);
strcat(Result,Sum);
}
if(carry)
strcat(Result,"1");
strset(Data,NULL);
strcpy(Data,Result);
}
elseif(strcmp(Operator,"-")==0)
{
int borrow=0;
int difference=0;
int digit_1=0;
int digit_2=0;
char Difference[5]={NULL};
for(int i=0;i<length;i++)
{
digit_1=(int(Data[i])-48);
digit_2=(int(Temp[i])-48);
difference=(digit_1-digit_2-borrow);
if(difference<0)
{
difference+=10;
borrow=1;
}
else
borrow=0;
itoa(difference,Difference,10);
strcat(Result,Difference);
}
strset(Data,NULL);
strcpy(Data,Result);
}
}
while(1);
strrev(Data);
cout<<Data<<endl;
File.getline(Data,50);
}
File.close( );
getch( );
return 0;
}