10035 - Primary Arithmetic
Moderator: Board moderators
Re: 10035 - primary arithmetic help!
I apologize if that was me that deleted the account - I had something like "if joined in last 5 days and has more than 5 posts, delete".
I eyeballed the account names, none of them looked legit so I might have missed yours.
Sorry about that.
Darko
I eyeballed the account names, none of them looked legit so I might have missed yours.
Sorry about that.
Darko
Re: 10035 - primary arithmetic help!
why WA??
brianfry plz help me to find the mistake.
brianfry plz help me to find the mistake.
Code: Select all
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
string a,b;
int len1,len2,carry,count,i;
while(cin>>a>>b)
{
if(a=="0" && b=="0")break;
count=0;
len1=a.size();
reverse(a.begin(),a.end());//ekhane pointer arithmatic khatbe na
len2=b.size();
reverse(b.begin(),b.end());
len1=len1<len2?len1:len2;
carry=0;
for(i=0;i<len1;++i)
{
carry=(a[i]-48)+(b[i]-48)+carry;
if(carry>9)
{
carry=1;//incase of addition carry is 1
++count;
}
else carry=0;
}
if(count==0)printf("No carry operation.\n");
else if(count==1)printf("%d carry operation.\n", count);
else if(count>1)printf("%d carry operations.\n", count);
a.clear();
b.clear();
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035 - primary arithmetic help!
It looks like you figured it out
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 8
- Joined: Fri Jan 17, 2014 3:35 pm
10035-Primary Arithmetic
Help! I've checked many bundary cases, and the result is correct. But I still got wrong answer, why?
#include <stdio.h>
#include<stdlib.h>
int main() {
long long int num1;
long long int num2;
int carry=0;
int check=0;
while(1){
scanf("%lld %lld",&num1,&num2);
if(num1==0&&num2==0)
break;
while(num1!=0||num2!=0){
if(check==0){
if(num1%10+num2%10>=10){
carry++;
check=1; }
else
check=0; }
else{
if(num1%10+num2%10+1>=10){
carry++;
check=1; }
else
check=0; }
num1=num1/10;
num2=num2/10;
}
if(carry==0)
printf("No carry operation.\n");
else {
if(carry==1)
printf("1 carry operation.\n");
else
printf("%d carry operations.\n",carry); }
carry=0; }
system("pause"); }
#include <stdio.h>
#include<stdlib.h>
int main() {
long long int num1;
long long int num2;
int carry=0;
int check=0;
while(1){
scanf("%lld %lld",&num1,&num2);
if(num1==0&&num2==0)
break;
while(num1!=0||num2!=0){
if(check==0){
if(num1%10+num2%10>=10){
carry++;
check=1; }
else
check=0; }
else{
if(num1%10+num2%10+1>=10){
carry++;
check=1; }
else
check=0; }
num1=num1/10;
num2=num2/10;
}
if(carry==0)
printf("No carry operation.\n");
else {
if(carry==1)
printf("1 carry operation.\n");
else
printf("%d carry operations.\n",carry); }
carry=0; }
system("pause"); }
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035-Primary Arithmetic
End your code with
return 0;
instead of
system("pause");
return 0;
instead of
system("pause");
Check input and AC output for thousands of problems on uDebug!
Re: 10035-Primary Arithmetic plssssss help get so much WA
Code: Select all
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main()
{
long long int i,j,k,t_case,c,d,temp,temp2,temp3,a[1000],b[1000],rev,rev1,index,index2,count,sum;
long long int sum2;
while(cin >> c >> d)
{
if(c==0&&d==0)
{
break;
}
temp=c;
temp2=d;
index=0;
index2=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
if(temp==0)
{
a[index++]=temp;
}
while(temp!=0)
{
rev=temp%10;
a[index++]=rev;
temp=temp/10;
}
if(temp2==0)
{
b[index2++]=temp;
}
while(temp2!=0)
{
rev1=temp2%10;
b[index2++]=rev1;
temp2=temp2/10;
}
count=0;
sum=0;
sum2=0;
if(index>=index2)
{
for(i=0;i<index;i++)
{
temp3=a[i]+b[i]+sum;
sum2=sum2+temp3;
if(temp3>9)
{
sum=1;
}
else if(sum2==1&&i==(index-1))
{
sum=1;
}
else if(temp3<=9)
{
sum=0;
}
if(sum==1)
{
count++;
}
}
}
else if(index2>=index)
{
for(i=0;i<index2;i++)
{
temp3=a[i]+b[i]+sum;
sum2=sum2+temp3;
if(temp3>9)
{
sum=1;
}
else if(sum2==1&&i==(index2-1))
{
sum=1;
}
else if(temp3<=9)
{
sum=0;
}
if(sum==1)
{
count++;
}
}
}
if(count==0)
{
printf("No carry operation.\n");
}
if(count>0)
{
printf("%lld carry operations.\n",count);
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035-Primary Arithmetic
1 carry operation.
not
1 carry operations.
not
1 carry operations.
Check input and AC output for thousands of problems on uDebug!
Re: 10035-Primary Arithmetic
again WA @brianfry713 

-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035-Primary Arithmetic
Post your updated code.
Check input and AC output for thousands of problems on uDebug!
Re: 10035-Primary Arithmetic
thnks @brianfry713 i got ac some mistake in counting thnks thnks thnks thnk u very much @brianfry713
thnks again


thnks again
Re: 10035-Primary Arithmetic
AC
Last edited by TLEorWA on Tue Mar 11, 2014 11:45 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035-Primary Arithmetic
Try input:
809 111
0 0
809 111
0 0
Check input and AC output for thousands of problems on uDebug!
Re: 10035-Primary Arithmetic
still WA....
@brianfry713
Here is my updated code..
why!

Here is my updated code..
why!
Last edited by TLEorWA on Tue Mar 11, 2014 11:45 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10035-Primary Arithmetic
Try input:
90 90
0 0
90 90
0 0
Check input and AC output for thousands of problems on uDebug!
Re: 10035-Primary Arithmetic
thnx brianfry713
AC
