Hi i am trying to solve above problem and getting WA. Help.
#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
char a[1000];
int i,b=0,c=0,d=0;
fflush(stdin);
gets(a);
fflush(stdin);
gets(a);
for(i=0;a[i]!=' ';i++)
{
if(a[i]=='m')
{
b=-1;
break;
}
b=b*10+(a[i]-'0');
}
for(;a[i]!=' ';i++);
i+=3;
for(;a[i]!=' ';i++)
{
if(a[i]=='m')
{
c=-1;
break;
}
c=c*10+(a[i]-'0');
}
for(;a[i]!=' ';i++);
i+=3;
for(;a[i]!='\0';i++)
{
if(a[i]=='m')
{
d=-1;
break;
}
d=d*10+(a[i]-'0');
}
if(b==-1) printf("%d + %d = %d\n",d-c,c,d);
else if(c==-1) printf("%d + %d = %d\n",b,d-b,d);
else printf("%d + %d = %d\n",b,c,b+c);
}
return 0;
}
PS — I got AC. I was getting WA because there were many blank lines in input.
Auto comment: topic has been updated by dush1729 (previous revision, new revision, compare).
Auto comment: topic has been updated by dush1729 (previous revision, new revision, compare).
You got AC, but here is an awesome trick, that would make your code much simpler.
For reading you can use, the full power of scanf!
With this trick, you can work with the three number without much coding.
Have a nice day, hope it's useful for you! :)