10035 - Primary Arithmetic
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic
That is AC code.
Check input and AC output for thousands of problems on uDebug!
Re: 10035 - Primary Arithmetic
Thank you. I don't know why I always got wrong answer yesterday with this code.
But I got AC now. Thanks.
But I got AC now. Thanks.
Re: 10035 - Primary Arithmetic
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic
The sample output has "3 carry operations." not "3 carry operation."
Check input and AC output for thousands of problems on uDebug!
Re: 10035 - Primary Arithmetic
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic
Input:Correct output:
Code: Select all
999 1
0 0
Code: Select all
3 carry operations.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 14
- Joined: Tue Sep 24, 2013 4:35 pm
uva 10035
I got WA more than 7 times in this problem and could not find the bug..
my code
Thank You..
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: uva 10035
Try input:
Code: Select all
9 9
5 4
0 0
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Thu Oct 24, 2013 7:06 pm
uva 10035 Why WA ?? can not understand .
#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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: uva 10035 Why WA ?? can not understand .
Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!
Re: 10035 - Primary Arithmetic
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]
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]
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic
1877803158 298799547
8 carry operations.
8 carry operations.
Check input and AC output for thousands of problems on uDebug!
-
- 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
Try input:Output should be:
Code: Select all
123 0
0 0
Code: Select all
No carry operation.
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - primary arithmetic help!
Try input:
0 999999999
0 0
0 999999999
0 0
Check input and AC output for thousands of problems on uDebug!
Re: 10035 - primary arithmetic help!
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.
Anyways, much appreciate it.