
10035 - Primary Arithmetic
Moderator: Board moderators
Re: why WA........to 10035????????/////
thank's a lotttttttt...........i got AC 

Re: 10035 - Primary Arithmetic
// 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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic
Try this input:
Code: Select all
9 1
1 8
0 0
Check input and AC output for thousands of problems on uDebug!
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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic... Why I got WA???
Try your code on the sample I/O given in the problem statement.
Check input and AC output for thousands of problems on uDebug!
Re: 10035 - Primary Arithmetic... Why I got WA???
ohhhhhhhhhhhh i realized a stupid mistake in my code....
Thanks again brian.....
Thanks again brian.....
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;
}
#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.
Re: 10035 - Primary Arithmetic... Why I got WA???
Please spot out the problem! I am not able to find any!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic... Why I got WA???
There should be a '.' at the end of each line.
Check input and AC output for thousands of problems on uDebug!
Re: 10035 - Primary Arithmetic... Why I got WA???
Thanks for pointing out the mistake. But after correction, it's still giving WA!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - Primary Arithmetic... Why I got WA???
Try input 99999999 1
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 2
- Joined: Sun Jun 24, 2012 10:38 am
why wa in 10035
// 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;
}
#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;
}
-
- New poster
- Posts: 2
- Joined: Sun Jun 24, 2012 10:38 am
Re: why wa in 10035
i can't resolve the problem in this code. plz anyone help viewing my error and what should i do to resolve.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: why wa in 10035
Input:
Code: Select all
909 909
0 0
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 21
- Joined: Mon Jun 18, 2012 12:52 am
- Location: Dhaka, Bangladesh.
- Contact:
Re: 10035 - Primary Arithmetic
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:
Sample Output:
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.
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
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.