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

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

Moderator: Board moderators

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

Postby jocker1 » Sat May 19, 2012 11:30 pm

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

Postby brianfry713 » Mon May 21, 2012 11:07 pm

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

Postby jocker1 » Wed May 23, 2012 9:43 am

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

Postby Reveur » Mon May 28, 2012 11:02 pm

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

Postby Reveur » Thu May 31, 2012 2:27 pm

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

Postby brianfry713 » Fri Jun 01, 2012 1:27 am

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

Postby Reveur » Fri Jun 01, 2012 10:34 am

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

Postby brianfry713 » Fri Jun 01, 2012 11:46 pm

Try input 99999999 1
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to Volume CXII

Who is online

Users browsing this forum: No registered users and 0 guests