## 10035 - Primary Arithmetic

Moderator: Board moderators

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am

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

Darko

New poster
Posts: 17
Joined: Sat Dec 07, 2013 8:00 am

### Re: 10035 - primary arithmetic help!

why WA??
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;
}
``````

brianfry713
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!

terry646623
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"); }

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

### Re: 10035-Primary Arithmetic

return 0;
system("pause");
Check input and AC output for thousands of problems on uDebug!

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

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

}
``````

brianfry713
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.
Check input and AC output for thousands of problems on uDebug!

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

### Re: 10035-Primary Arithmetic

again WA @brianfry713

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

### Re: 10035-Primary Arithmetic

Check input and AC output for thousands of problems on uDebug!

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

### Re: 10035-Primary Arithmetic

thnks @brianfry713 i got ac some mistake in counting thnks thnks thnks thnk u very much @brianfry713
thnks again

TLEorWA
New poster
Posts: 12
Joined: Sat Mar 01, 2014 12:56 pm

### Re: 10035-Primary Arithmetic

AC
Last edited by TLEorWA on Tue Mar 11, 2014 11:45 pm, edited 1 time in total.

brianfry713
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
Check input and AC output for thousands of problems on uDebug!

TLEorWA
New poster
Posts: 12
Joined: Sat Mar 01, 2014 12:56 pm

### Re: 10035-Primary Arithmetic

still WA.... @brianfry713
Here is my updated code..

why!
Last edited by TLEorWA on Tue Mar 11, 2014 11:45 pm, edited 1 time in total.

brianfry713
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
Check input and AC output for thousands of problems on uDebug!

TLEorWA
New poster
Posts: 12
Joined: Sat Mar 01, 2014 12:56 pm

### Re: 10035-Primary Arithmetic

thnx brianfry713 AC