1 / 2
Feb 2011

#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
bool isNumber(char *str)
{
	for(int i=0;i<strlen(str);i++)
	{
		if(!isdigit(str[i]))
		{
			return false;
		}
	}
}
int main()
{
	int count,array_1[1000],array_2[1000],array_3[1000],i=0,j=0,k=0;	
	char num1[1000],num2[1000],res[1000],temp_buf[1000];
	cin>>count;
	while(count--)
	{
	char operator_1,equal;	
	int number1=0,number2=0,result=0;
	gets(temp_buf);
	cin>>num1;
	cin>>operator_1;
	cin>>num2;	 
	number1= atoi(num1);
	number2= atoi(num2);
	if(isNumber(num1))
	{
      number1=atoi(num1);
	  array_1[i]=number1;
	  i++;
	}	
	if(isNumber(num2))
	{
      number2=atoi(num2);
	  array_2[j]=number2;
	  j++;
	}
	cin>>equal;
	cin>>res;
	result=atoi(res);
	if(!isNumber(res))
	{
      result = number1+number2;
	  array_3[k]=result;
	  k++;	  
	}
	else
	{
	  result=atoi(res);
	  array_3[k]=result;
	  k++;		
	}
	if(!isNumber(num1))
	{
      number1= result-number2;
	  array_1[i]=number1;
	  i++;
	}	
    if(!isNumber(num2))
{
  number2= result-number1;
  array_2[j]=number2;
  j++;
}	
}
//	getchar();getchar();
    for(int a=0,b=0,c=0;a<k,b<k,c<k;a++,b++,c++)
	{
		cout<<array_1[a]<<" + "<<array_2[b]<<" = "<<array_3[c]<<endl;
	}
    return 0;
}

I'm able to get the exact result as specified in the problem desc. But getting WA in SPOJ.

  • created

    Feb '11
  • last reply

    Feb '11
  • 1

    reply

  • 109

    views

  • 2

    users

Where did you come up with 1000?

You don't need to store the output of each test case and output them all at the end. Read a testcase, print the output, move to the next test case. The judge only looks at stdout. To mimic this you can redirect stdin and stdout to a file using the command line:
./test test.out