I'm having a problem in submitting a problem named "Money Transformation" on Popular coding site codechef..I get runtime error name SIG SEGV
every time I submit the solution..after some search on google I found this is some kind of segmentation fault..I tried all the possible solutions given in Codechef's FAQ but could not get it correct..Also this error must be compiler specific I'm using CodeBlock(12.1) on my machine with its minigw compiler and my program is running perfectly fine..Please Help me understand the problem and solve it..
Below is my program (after I edited it as per codechef's faq's solution)
#include <iostream>
using namespace std;
int i=0;
class money
{
public:
int a[101],b[101];
money()
{
for(int t=0;t<102;t++)
{
a[101]=0;
b[101]=0;
}
}
};
money m;
void swp(int &a,int &b)
{
int temp=0;
temp=a;
a=b;
b=temp;
}
int maximum()
{
int x=0;
m.a[100]=m.a[0];
m.b[100]=m.b[0];
for(int j=1;j<=(i+1);j++)
{
if(m.a[j]>m.a[100])
{
m.a[100]=m.a[j];
m.b[100]=m.b[j];
x=j;
}
if(m.a[j]==m.a[100])
{
if(m.b[i]>m.b[100])
{
m.a[100]=m.a[j];
m.b[100]=m.b[j];
x=j;
}
}
}
return x;
}
void moneytransform(int a,int b,int c)
{
m.a[0]=a;
m.b[0]=b;
while(true)
{
if(c>m.b[i]&&m.a[i]>0)
{
m.a[i+1]=m.a[i]-1;
m.b[i+1]=m.b[i]+100-c;
}
else
{
m.a[i+1]=m.a[i];
m.b[i+1]=m.b[i]-c;
}
swp(m.a[i+1],m.b[i+1]);
if((m.b[i]<c&&m.a[i]==0)||(m.a[i+1]>100||m.b[i+1]>100))
{
return;
}
i++;
}
}
int main()
{
int T,A,B,C,M;
do
{
cin>>T;
}while(T>40);
int noc=1;
while(noc<=T)
{
do
{
cin>>A>>B>>C;
}while(A<0&&B<0&&C<0&&A>100&&B>100&&C>100);
moneytransform(A,B,C);
M=maximum();
cout<<M;
noc++;
}
return 0;
}
and the link to the codechef problem is..http://www.codechef.com/problems/MONTRANS/