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

artless
New poster
Posts: 7
Joined: Tue Nov 22, 2011 2:01 pm

Re: why WA........to 10035????????/////

Post by artless »

thank's a lotttttttt...........i got AC :wink:
tonmoy002
New poster
Posts: 1
Joined: Mon Apr 23, 2012 1:25 am

Re: 10035 - Primary Arithmetic

Post by tonmoy002 »

// giving wrong answer .But why???


#include<iostream>
using namespace std;
int main()
{
unsigned int a,b,m1,m2,count,save=0;
while(cin>>a>>b)
{
count=0;
if(a==0&&b==0) break;

while(1)
{
if(a==0&&b==0)
break;
m1=a%10;
m2=b%10;
a=a/10;
b=b/10;
if((m1+m2+save)>9)
{
count++;
save=1;
}
else save=0;
}
if(count==0)
cout<<"No carry operation."<<endl;
else if(count==1)
cout<<count<<" carry operation."<<endl;
else if(count>1)
cout<<count<<" carry operations."<<endl;
}
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 »

Try this input:

Code: Select all

9 1
1 8
0 0
Check input and AC output for thousands of problems on uDebug!
jocker1
New poster
Posts: 5
Joined: Sat May 19, 2012 11:10 pm

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

Post by jocker1 »

#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;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 »

Try your code on the sample I/O given in the problem statement.
Check input and AC output for thousands of problems on uDebug!
jocker1
New poster
Posts: 5
Joined: Sat May 19, 2012 11:10 pm

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

Post by jocker1 »

ohhhhhhhhhhhh i realized a stupid mistake in my code....
Thanks again brian.....
Reveur
New poster
Posts: 3
Joined: Fri May 18, 2012 3:34 pm

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

Post by Reveur »

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

Post by Reveur »

Please spot out the problem! I am not able to find any!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 »

There should be a '.' at the end of each line.
Check input and AC output for thousands of problems on uDebug!
Reveur
New poster
Posts: 3
Joined: Fri May 18, 2012 3:34 pm

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

Post by Reveur »

Thanks for pointing out the mistake. But after correction, it's still giving WA!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 »

Try input 99999999 1
Check input and AC output for thousands of problems on uDebug!
shahedicpc
New poster
Posts: 2
Joined: Sun Jun 24, 2012 10:38 am

why wa in 10035

Post by shahedicpc »

// Primary arithmatic wa
#pragma warning (disable: 4786)
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>

using namespace std;

int main()
{
long int x,y;


while(cin>>x>>y)
{
if(x==0&& y==0)break;
int carry=0,sum=0;
bool flag=false;

while(x%10||y%10) // suppose x=999 and y=1
{
sum=x%10+y%10+flag;
x/=10;
y/=10;
if(sum>=10){

flag=true;
carry++;
sum=0;

}

}

if(carry==0)
cout<<"No carry operation."<<endl;
else if(carry==1)
cout<<"1 carry operation."<<endl;
else
cout<<carry<<" carry operations."<<endl;
}

return 0;
}
shahedicpc
New poster
Posts: 2
Joined: Sun Jun 24, 2012 10:38 am

Re: why wa in 10035

Post by shahedicpc »

i can't resolve the problem in this code. plz anyone help viewing my error and what should i do to resolve.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: why wa in 10035

Post by brianfry713 »

Input:

Code: Select all

909 909
0 0
Check input and AC output for thousands of problems on uDebug!
PromeNabid
New poster
Posts: 21
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.
Contact:

Re: 10035 - Primary Arithmetic

Post by PromeNabid »

Thanks brianfry, your cases helped a lot.
Quiet easy problem, but got 3 WA and 2 Compile Error followed by Accepted.
This cases might help.
Sample Input:

Code: Select all

123 456
555 555

123 594
1234 5678910
12354 9125478654
321456 21
56324 
987
1 9
333 0
0 1
11 99

9999999999 
9999999999
9999999999 1

99999999 1
0 0
Sample Output:

Code: Select all

No carry operation.
3 carry operations.
1 carry operation.
2 carry operations.
3 carry operations.
No carry operation.
3 carry operations.
1 carry operation.
No carry operation.
No carry operation.
2 carry operations.
10 carry operations.
10 carry operations.
8 carry operations.
1 more thing, using "strrev()" isn't a good idea(may be I got CE for this), might not work in GCC which is used by UVa.
Post Reply

Return to “Volume 100 (10000-10099)”