Page 19 of 22

Re: 10035 - Primary Arithmetic

Posted: Tue May 21, 2013 2:46 am
by brianfry713
That is AC code.

Re: 10035 - Primary Arithmetic

Posted: Tue May 21, 2013 4:05 pm
by da729vid
Thank you. I don't know why I always got wrong answer yesterday with this code.
But I got AC now. Thanks.

Re: 10035 - Primary Arithmetic

Posted: Thu Jun 06, 2013 11:28 pm
by RoniphpBB
Why i am getting WA plz help anyone

Code: Select all

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string.h>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
	 unsigned long int a,b,m,n,t;
	 int count=0;
	 while(1)
	 {
	      cin>>a>>b;
		  if(a==0&&b==0){ break;}
		  while(a%10!=0&&b%10!=0)
		  {
		  m=a%10,n=b%10;
		  t=m+n;
		  if(t>9)
		  {
				count++;
		  }
          a=a/10,b=b/10;
		  t=0;m=0,n=0;
		  }
		  if(count==0){ cout<<"No carry operation."<<endl; }
		  else if(count>0)
		  {
			   cout<<count<<" carry operation."<<endl;
		  }
		 count=0;
	  }
	 return 0;

}


Re: 10035 - Primary Arithmetic

Posted: Tue Jun 11, 2013 3:32 am
by brianfry713
The sample output has "3 carry operations." not "3 carry operation."

Re: 10035 - Primary Arithmetic

Posted: Tue Jun 25, 2013 11:02 am
by RoniphpBB
Why i am getting WA all test cases are show correct plz help.
give me some test case

Code: Select all

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string.h>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
	 unsigned long int a,b,m,n,t;
	 int count=0;
	 while(cin>>a>>b)
	 {

		  if(a==0&&b==0){ break;}
		  while(a!=0&&b!=0)
		  {
		  m=a%10,n=b%10;

		  t=m+n;
		  if(t>=10)
		  {
				count++;
		  }
          a=a/10,b=b/10;
		  t=0;m=0,n=0;
		  }
		  if(count==0){ cout<<"No carry operation."<<endl; }
		  else if(count==1){cout<<count<<" carry operation."<<endl;}
		  else
		  {
			   cout<<count<<" carry operations."<<endl;
          }
		 count=0;
	  }
	 return 0;

}


Re: 10035 - Primary Arithmetic

Posted: Tue Jun 25, 2013 11:17 pm
by brianfry713
Input:

Code: Select all

999 1
0 0
Correct output:

Code: Select all

3 carry operations.

uva 10035

Posted: Tue Sep 24, 2013 4:48 pm
by walking_hell
I got WA more than 7 times in this problem and could not find the bug..
my code

Code: Select all

#include<stdio.h>
int main()
{
    long int num1,num2,x,y,carry,crry=0;
    while(scanf(" %ld %ld",&num1,&num2)==2 && (num1!=0 || num2!=0))
    {
        carry=0;

        while(num1!=0 || num2!=0)
        {
            x=num1%10;
            y=num2%10;
            num1=num1/10;
            num2=num2/10;
            if(x+y+crry>=10)
            {carry++;
            crry=1;



            }
            else
            crry=0;

        }
        if(carry==0)
        printf("No carry operation.\n");
        else if(carry==1)
        printf("1 carry operation.\n");
        else
        printf("%ld carry operations.\n",carry);



    }



    return 0;
}
Thank You..

Re: uva 10035

Posted: Tue Sep 24, 2013 10:42 pm
by brianfry713
Try input:

Code: Select all

9 9
5 4
0 0

uva 10035 Why WA ?? can not understand .

Posted: Wed Oct 30, 2013 7:35 am
by souravpaulkundu
#include<stdio.h>
#include<stdlib.h>

int main()
{ unsigned long int a,b,c,d;
int count=0,e=0;
while(scanf("%lu%lu",&a,&b)==2)
{ if(a<1000000000&&b<1000000000)
{
if(a==0&&b==0)
break;
while(a>9||b>9)
{
c=a%10;
d=b%10;
a=a/10;
b=b/10;
c=c+d+e;
if(c>9)
{ e=1;
count++;
}
else e=0;
}
if(count==0)
printf("No carry operation.\n");
else
printf("%d carry operations.\n",count);
count=0;

}
}

return 0;

}

Re: uva 10035 Why WA ?? can not understand .

Posted: Wed Oct 30, 2013 7:59 pm
by brianfry713
Try running your code on the sample input.

Re: 10035 - Primary Arithmetic

Posted: Mon Nov 04, 2013 6:15 pm
by Sadique
Why I get wrong answer? I can not understand.[code#include<stdio.h>
int main()
{
long long int a,b,c,d,rem,rem2,k,flag;
while(1)
{
k=0;
scanf("%lld%lld",&c,&d);
if(c<=d)
{
a=d;
b=c;
}
if(c>=d)
{
a=c;
b=d;
}
if(a==0&&b==0)
{
break;
}
flag=0;
for(;;)
{
rem=a%10;
rem2=b%10;
if(flag==1&&rem!=0)
rem+=1;
a=a/10;
b=b/10;
flag=0;
if((rem+rem2)>9)
{
k++;
flag=1;
}
if(a==0&&b==0)
break;
}
if(k==0)
{
printf("No carry operation.\n");
}
else
{
if(k==1)
printf("%lld carry operation.\n",k);
else
printf("%lld carry operations.\n",k);
}
}
return 0;
}][/code]

Re: 10035 - Primary Arithmetic

Posted: Tue Nov 05, 2013 12:48 am
by brianfry713
1877803158 298799547
8 carry operations.

Re: Why i m getting wrong answer. please help me. the code i

Posted: Tue Nov 26, 2013 2:37 am
by brianfry713
Try input:

Code: Select all

123 0
0 0
Output should be:

Code: Select all

No carry operation.

Re: 10035 - primary arithmetic help!

Posted: Tue Dec 03, 2013 11:47 pm
by brianfry713
Try input:
0 999999999
0 0

Re: 10035 - primary arithmetic help!

Posted: Thu Dec 05, 2013 7:12 am
by jcbiznoff
Thanks brainfry. Seems like I wasnt handling buffer overflow correctly. BTW dont know why the post got deleted. My account also got deleted as well.
Anyways, much appreciate it.