http://www.spoj.com/problems/ABSYS/.
I am getting run time error in this spoj problem i have tried all the test cases but it’s not working
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
string str;
cin>>str;
char s1[1000],s2[1000],s3[1000];
int j=0,k=0,l=0,p=0,occ_of_plus,occ_of_equal,occ_of_m;
for(int i=0;str[i]!='+';i++)//finding occurence of + in the string
{
s1[j]=str[i];
j++;
}
s1[j]='\0';
j++;
for(int i=j;str[i]!='=';i++)//finding occurence of '=' in string
{
s2[k]=str[i];
k++;
p=i;
}
s2[k]='\0';
k++;
for(int i=p+2;i<str.size();i++)
{
s3[l]=str[i];
l++;
}
s3[l]='\0';
l++;
for(int i=0;i<str.size();i++)
{
if(str[i]=='m')
occ_of_m=i+1;
if(str[i]=='+')
occ_of_plus=i+1;
if(str[i]=='=')
occ_of_equal=i+1;
}
if(occ_of_m>occ_of_equal)
{
int a=atoi(s1);
int b=atoi(s2);
cout<<s1<<"+"<<s2<<"="<<a+b<<endl;
}
if(occ_of_m>occ_of_plus&&occ_of_m<occ_of_equal)
{
int a=atoi(s1);
int b=atoi(s3);
cout<<s1<<"+"<<b-a<<"="<<s3<<endl;
}
if(occ_of_m<occ_of_plus)
{
int a=atoi(s2);
int b=atoi(s3);
cout<<b-a<<"+"<<s2<<"="<<s3<<endl;
}
printf("\n");
}
return 0;
}