I don't understand what was meant by that Floating Point Exception generated during submission my code of 10875 (Big Math).
Code: Select all
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char input[10][1000];
char inputP[100][5][3];
int operands[100];
char opt[100];
int t;
int ooo[256];
char abc[100];
int xyz[100];
const char p[14][5][3]=
{
'0','0','0',
'0','.','0',
'0','.','0',
'0','.','0',
'0','0','0',
'.','0','.',
'.','0','.',
'.','0','.',
'.','0','.',
'.','0','.',
'0','0','0',
'.','.','0',
'0','0','0',
'0','.','.',
'0','0','0',
'0','0','0',
'.','.','0',
'0','0','0',
'.','.','0',
'0','0','0',
'0','.','0',
'0','.','0',
'0','0','0',
'.','.','0',
'.','.','0',
'0','0','0',
'0','.','.',
'0','0','0',
'.','.','0',
'0','0','0',
'0','.','.',
'0','.','.',
'0','0','0',
'0','.','0',
'0','0','0',
'0','0','0',
'.','.','0',
'.','.','0',
'.','.','0',
'.','.','0',
'0','0','0',
'0','.','0',
'0','0','0',
'0','.','0',
'0','0','0',
'0','0','0',
'0','.','0',
'0','0','0',
'.','.','0',
'.','.','0',
'.','0','.',
'.','0','.',
'0','0','0',
'.','0','.',
'.','0','.',
'.','.','.',
'.','.','.',
'0','0','0',
'.','.','.',
'.','.','.',
'0','.','0',
'0','.','0',
'.','0','.',
'0','.','0',
'0','.','0',
'.','0','.',
'.','.','.',
'0','0','0',
'.','.','.',
'.','0','.',
};
int whatSymbol(int i)
{
int j;
int w=0;
for(j=0; j<14; j++)
{
if(memcmp(inputP[i],p[j],sizeof(inputP[i]))==0)
{
w = j;
}
}
return w;
}
void findHighestOperator()
{
int h=1;
int i=0,j;
ooo['+']=1;
ooo['-']=1;
ooo['*']=2;
ooo['/']=2;
for(j=0; j<t; j++)
{
if(ooo[opt[j]]>h)
{
h = ooo[opt[j]];
i = j;
}
}
switch(opt[i])
{
case '+':
{
operands[i] = operands[i]+operands[i+1];
break;
}
case '-':
{
operands[i] = operands[i]-operands[i+1];
break;
}
case '*':
{
operands[i] = operands[i]*operands[i+1];
break;
}
case '/':
{
operands[i] = operands[i]/operands[i+1];
break;
}
}
memcpy(abc,&opt[i+1],sizeof(&opt[i]));
memcpy(&opt[i],abc,sizeof(abc));
memcpy(xyz,&operands[i+2],sizeof(&operands[i+2]));
memcpy(&operands[i+1],xyz,sizeof(xyz));
}
int main()
{
int o,k;
char hh[100];
int i=0,j;
char m[1000];
int space=0;
int len;
char *pq=NULL;
int b;
int z=0;
int flag=0,flag2=0;
char op1[100];
int count=0;
int y;
int x;
char *ghi = NULL;
char *gh=NULL;
int xx,minus;
int c;
freopen("10875.in","r",stdin);
do
{
if(flag)
{
printf("\n");
}
flag=1;
space =0;
pq = NULL;
gets(m);
len = strlen(m);
for(j=0; j<len; j++)
{
if(m[j]==' ')
space++;
}
space++;
z=0;
while(len>0 || m[0]==' ')
{
pq = strtok(m," \n");
for(k=0; k<space; k++)
{
for(b=0; b<3; b++)
{
inputP[i][z][b] = pq[b];
}
pq = strtok(NULL," \n");
i = (i+1)%space;
}
gets(m);
len = strlen(m);
z++;
}
int count=0;
if(whatSymbol(0)==0 && space==1)
break;
for(i=0; i<space; i++)
{
x =whatSymbol(i);
if(x<=9)
{
op1[count++]=x+48;
op1[count]='\0';
}
else
{
if(x==10)
{
op1[count++]='+';
op1[count]='\0';
}
else if(x==11)
{
op1[count++]='-';
op1[count]='\0';
}
else if(x==12)
{
op1[count++]='*';
op1[count]='\0';
}
else
{
op1[count++]='/';
op1[count]='\0';
}
}
}
/*
Equation processing */
strcpy(hh,op1);
y=0;
t=0;
ghi = strtok(op1,"0123456789");
while(ghi)
{
opt[t++]=ghi[0];
ghi = strtok(NULL,"0123456789");
}
opt[t]='\0';
gh = strtok(hh,"+-*/");
while(gh)
{
operands[y++]=atoi(gh);
gh = strtok(NULL,"+-*/");
}
while((len = strlen(opt))>0)
{
findHighestOperator();
}
xx=operands[0];
minus=0;
if(xx<0)
{
xx = xx*(-1);
minus = 1;
}
char a[100];
for(int h=0; h<5; h++)
{
sprintf(a,"%d",xx);
c = strlen(a);
if(minus)
c++;
int f;
if(minus)
{
f = 11;
}
else
{
f=a[0]-'0';
}
for(o=0; o<c ; )
{
for(k=0; k<3; k++)
{
printf("%c",p[f][h][k]);
}
printf(" ");
if(minus)
{
f = a[o++]-'0';
}
else
{
f = a[++o]-'0';
}
}
printf("\n");
i=0;
}
}while(1);
return 0;
}
rahurprem.