## 10035 - Primary Arithmetic... Why I got WA???

Moderator: Board moderators

### 10035 - Primary Arithmetic... Why I got WA???

#include <iostream>
#include <algorithm>
using namespace std;

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

return 0;
}
jocker1
New poster

Posts: 5
Joined: Sat May 19, 2012 11:10 pm

### Re: 10035 - Primary Arithmetic... Why I got WA???

Try your code on the sample I/O given in the problem statement.
brianfry713
Guru

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

### Re: 10035 - Primary Arithmetic... Why I got WA???

ohhhhhhhhhhhh i realized a stupid mistake in my code....
Thanks again brian.....
jocker1
New poster

Posts: 5
Joined: Sat May 19, 2012 11:10 pm

### Re: 10035 - Primary Arithmetic... Why I got WA???

Why got WA? Giving correct output..

#include<stdio.h>
int main()
{
int i,j,temp,c=0, carry=0, a, b;
while(scanf("%d %d", &i, &j)==2)
{
if(i==0 && j==0)
{
break;
}
while((i!=0) || (j!=0))
{
a=i%10;
b=j%10;
if((carry+a+b)>9)
{
carry=(a+b)/10;
c++;
}
i=i/10;
j=j/10;
}
if(c==0)
{ printf("No carry operation.\n");}
else if(c==1)
{printf("1 carry operation.\n");}
else printf("%d carry operations.\n",c);
c=0;
carry=0;
}
return 0;
}
Last edited by Reveur on Fri Jun 01, 2012 10:35 am, edited 1 time in total.
Reveur
New poster

Posts: 3
Joined: Fri May 18, 2012 3:34 pm

### Re: 10035 - Primary Arithmetic... Why I got WA???

Please spot out the problem! I am not able to find any!
Reveur
New poster

Posts: 3
Joined: Fri May 18, 2012 3:34 pm

### Re: 10035 - Primary Arithmetic... Why I got WA???

There should be a '.' at the end of each line.
brianfry713
Guru

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

### Re: 10035 - Primary Arithmetic... Why I got WA???

Thanks for pointing out the mistake. But after correction, it's still giving WA!
Reveur
New poster

Posts: 3
Joined: Fri May 18, 2012 3:34 pm

### Re: 10035 - Primary Arithmetic... Why I got WA???

Try input 99999999 1
brianfry713
Guru

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