10035 - Primary Arithmetic

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10035 - Primary Arithmetic

Post by brianfry713 » Tue May 21, 2013 2:46 am

That is AC code.
Check input and AC output for thousands of problems on uDebug!

da729vid
New poster
Posts: 2
Joined: Mon May 20, 2013 9:21 pm

Re: 10035 - Primary Arithmetic

Post by da729vid » Tue May 21, 2013 4:05 pm

Thank you. I don't know why I always got wrong answer yesterday with this code.
But I got AC now. Thanks.

RoniphpBB
New poster
Posts: 10
Joined: Sat Feb 09, 2013 11:22 am

Re: 10035 - Primary Arithmetic

Post by RoniphpBB » Thu Jun 06, 2013 11:28 pm

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;

}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10035 - Primary Arithmetic

Post by brianfry713 » Tue Jun 11, 2013 3:32 am

The sample output has "3 carry operations." not "3 carry operation."
Check input and AC output for thousands of problems on uDebug!

RoniphpBB
New poster
Posts: 10
Joined: Sat Feb 09, 2013 11:22 am

Re: 10035 - Primary Arithmetic

Post by RoniphpBB » Tue Jun 25, 2013 11:02 am

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;

}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10035 - Primary Arithmetic

Post by brianfry713 » Tue Jun 25, 2013 11:17 pm

Input:

Code: Select all

999 1
0 0
Correct output:

Code: Select all

3 carry operations.
Check input and AC output for thousands of problems on uDebug!

walking_hell
New poster
Posts: 14
Joined: Tue Sep 24, 2013 4:35 pm

uva 10035

Post by walking_hell » Tue Sep 24, 2013 4:48 pm

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..

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: uva 10035

Post by brianfry713 » Tue Sep 24, 2013 10:42 pm

Try input:

Code: Select all

9 9
5 4
0 0
Check input and AC output for thousands of problems on uDebug!

souravpaulkundu
New poster
Posts: 1
Joined: Thu Oct 24, 2013 7:06 pm

uva 10035 Why WA ?? can not understand .

Post by souravpaulkundu » Wed Oct 30, 2013 7:35 am

#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;

}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 » Wed Oct 30, 2013 7:59 pm

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

Sadique
New poster
Posts: 1
Joined: Mon Nov 04, 2013 6:08 pm

Re: 10035 - Primary Arithmetic

Post by Sadique » Mon Nov 04, 2013 6:15 pm

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]

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10035 - Primary Arithmetic

Post by brianfry713 » Tue Nov 05, 2013 12:48 am

1877803158 298799547
8 carry operations.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 » Tue Nov 26, 2013 2:37 am

Try input:

Code: Select all

123 0
0 0
Output should be:

Code: Select all

No carry operation.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10035 - primary arithmetic help!

Post by brianfry713 » Tue Dec 03, 2013 11:47 pm

Try input:
0 999999999
0 0
Check input and AC output for thousands of problems on uDebug!

jcbiznoff
New poster
Posts: 1
Joined: Thu Dec 05, 2013 3:09 am

Re: 10035 - primary arithmetic help!

Post by jcbiznoff » Thu Dec 05, 2013 7:12 am

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.

Post Reply

Return to “Volume 100 (10000-10099)”