div24ever's blog

By div24ever, history, 5 years ago, In English,

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.

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Dushyant (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Dushyant (previous revision, new revision, compare).

»
5 years ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

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!

char t1[1000], t2[1000], t3[1000];
scanf("%s + %s = %s", &t1, &t2, &t3);

With this trick, you can work with the three number without much coding.

Have a nice day, hope it's useful for you! :)