Page 21 of 22

Re: 10035 - Primary Arithmetic

Posted: Thu May 29, 2014 6:10 pm
by muktadir.rhmn
please help. why WA???

Code: Select all

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
     char  num[2][11];
     int carry, ans, sumOfDigits, bigNumI, smallNumI, bigNumDigits, smallNumDigits, tmp;

    scanf("%s %s", num[0], num[1]);
    while(!(atoi(num[1]) == 0 && atoi(num[0]) == 0)){

        carry = 0;
        ans = 0;
        bigNumDigits = strlen(num[0]);
        smallNumDigits = strlen(num[1]);
        if ( bigNumDigits < smallNumDigits){
            tmp = bigNumDigits;
            bigNumDigits = smallNumDigits;
            smallNumDigits = tmp;
            bigNumI = 1;
            smallNumI = 0;
        }
        else{
            bigNumI = 0 ;
            smallNumI  = 1 ;
        }

        while( smallNumDigits--){
            sumOfDigits = num[bigNumI][--bigNumDigits] + num[smallNumI][smallNumDigits] + carry;
            if (sumOfDigits > 105){
                carry = 1;
                ans ++;
             }
             else
                carry = 0;
        }

        while(bigNumDigits-- && carry){
            sumOfDigits = num[bigNumI][bigNumDigits] + carry;
            if (sumOfDigits > 57){
                carry = 1;
                ans ++;
             }
             else
                carry = 0;
        }

        /* output*/
        if(ans)
            printf("%d carry operations.\n", ans);
        else
            printf("No carry operation.\n");

        scanf("%s %s", num[0], num[1]);

    }
   return 0;
}

Re: 10035 - Primary Arithmetic

Posted: Fri May 30, 2014 12:21 am
by lbv
muktadir.rhmn wrote:please help. why WA???
The code you posted doesn't pass the sample cases from the problem statement. Notice that the output from your program must match the expected output exactly. For example the strings "operation" and "operations" are considered different.

Re: 10035 - Primary Arithmetic

Posted: Fri May 30, 2014 4:15 am
by muktadir.rhmn
thnx a lot . got AC

Re: 10035 - Primary Arithmetic

Posted: Mon Jun 23, 2014 7:50 am
by zishan
Your code is ok,there is no minor mistake,please check your code with sample output

Re: 10035 - Primary Arithmetic

Posted: Sat Jul 19, 2014 5:39 pm
by fakeillution
please help,why WA?
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
while(1)
{
long long a,b;
cin>>a>>b;
if(a==0 && b==0)break;
if(a<b)swap(a,b);
int carry=0,flag=0,temp;
while(a)
{
if(flag)
temp=(a%10)+(b%10)+1;
else temp=(a%10)+(b%10);
if(temp>=10)
{

if(a/10)
{
carry++;
flag=1;
}
else
{
if(flag)carry++;
}
}
else flag=0;

a=a/10;
b=b/10;


}
if(!carry)
cout<<"No carry operation."<<endl;
else if(carry==1)
cout<<carry<<" carry operation."<<endl;
else
cout<<carry<<" carry operations."<<endl;
}
}

Re: 10035 - Primary Arithmetic

Posted: Sun Jul 20, 2014 10:34 am
by lighted
I don't understand why are you checking this,

Code: Select all

if(flag)carry++;

increasing

Code: Select all

carry++

must be done always if

Code: Select all

if temp>=10

It must be

Code: Select all

if(temp>=10)
{

  if(a/10)
  {
    carry++;
    flag=1;
  }
  else
  {
    carry++;
  }
}
Or it must be

Code: Select all

if(temp>=10)
{
  carry++;

  if(a/10)
    flag=1;
}
Don't forget to remove your code after getting accepted. 8)

10035 - Primary Arithmetic

Posted: Tue Jul 22, 2014 1:21 am
by ehsanulbigboss
OK!!!

Re: 10035 - Primary Arithmetic

Posted: Tue Jul 22, 2014 10:56 am
by lighted
You must search topics about your problem first.
Insert problem number 10035 into search box and you will get many explanations why your code may get WA.
http://acm.uva.es/board/search.php?keyw ... 2e7ff678c7

After first case you forget to set n to zero. Add line n = 0;

Code: Select all

while (scanf("%ld %ld",&x,&y)==2)
{
n = 0;
if (x==0 && y==0)
break;
Don't forget to remove your code after getting accepted. 8)

Re: 10035 - Primary Arithmetic

Posted: Mon Aug 18, 2014 1:53 am
by axelblaze
I've tested some critical I/Os but still getting WA.
please help...

Code: Select all

Removed after AC

Re: 10035 - Primary Arithmetic

Posted: Mon Aug 18, 2014 3:57 am
by lighted
My advice to you -> always copy/paste output format from sample or problem description. :)
Your output

Code: Select all

1 carry operations.
Sample output

Code: Select all

1 carry operation.

Re: 10035 - Primary Arithmetic

Posted: Mon Aug 18, 2014 9:15 am
by axelblaze
Thanks lighted... How silly of me...! :P

Re: 10035 - Primary Arithmetic

Posted: Sun Aug 31, 2014 11:40 pm
by battirunner
why WA, checked a lot,,,, pleas help.
#include<stdio.h>
#include<string.h>
int main()
{
char a[14],b[14];
int c=0,i,l,carry=0;
while(1)
{
scanf("%s%s",a,b);
if(a[0]=='0'&&b[0]=='0')
break;
i=strlen(a);
l=strlen(b);
i--;
l--;
while(i>=0&&l>=0)
{


if(((a+b[l])+carry-96)>9)
{
c++;
carry=1;
}
else
carry=0;

i--;
l--;

}

if(i>l)
{
if((a+carry)>57)
c++;
}
else if(l>i)
{
if((b[l]+carry)>57)
c++;
}
if(c==0)
printf("No ");
else
printf("%d ",c);


printf("carry operation");
if(c<2)
printf(".\n");
else
printf("s.\n");


c=0;
a[0]='\0';
b[0]='\0';
carry=0;
}
return 0;
}

Re: 10035 - Primary Arithmetic

Posted: Wed Sep 03, 2014 5:15 pm
by lighted
Input

Code: Select all

999 1
Output

Code: Select all

3 carry operations

Re: 10035 - Primary Arithmetic

Posted: Wed Sep 03, 2014 6:24 pm
by battirunner
what a childish calculation mistake..........
thanks a lot

Re: 10035 - Primary Arithmetic

Posted: Fri Sep 12, 2014 6:34 pm
by palashcse2k8
why WA ???
please help...

#include <iostream>

using namespace std;

int main()
{
long long int a,b;
while (cin>>a>>b && a!=0 && b!=0)
{
int r=0,c=0;
while (a||b)
{
r = (a%10 + b%10 + r)/10;
a=a/10;
b=b/10;
c+=r;
}
if(c==0)
cout<<"No carry operation."<<endl;
else if (c==1)
cout<<c<<" carry operation."<<endl;
else
cout<<c<<" carry operations."<<endl;
}
return 0;
}