Page 20 of 22

Re: 10035 - primary arithmetic help!

Posted: Fri Dec 06, 2013 7:33 pm
by Darko
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

Re: 10035 - primary arithmetic help!

Posted: Sun Jan 05, 2014 3:36 pm
by sady
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;
}

Re: 10035 - primary arithmetic help!

Posted: Wed Jan 15, 2014 12:52 am
by brianfry713
It looks like you figured it out

10035-Primary Arithmetic

Posted: Fri Jan 17, 2014 3:43 pm
by terry646623
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"); }

Re: 10035-Primary Arithmetic

Posted: Mon Jan 20, 2014 9:08 pm
by brianfry713
End your code with
return 0;
instead of
system("pause");

Re: 10035-Primary Arithmetic plssssss help get so much WA

Posted: Mon Jan 27, 2014 6:55 pm
by cse dipto

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;

}

Re: 10035-Primary Arithmetic

Posted: Mon Jan 27, 2014 10:49 pm
by brianfry713
1 carry operation.
not
1 carry operations.

Re: 10035-Primary Arithmetic

Posted: Wed Jan 29, 2014 7:40 pm
by cse dipto
again WA @brianfry713 :(

Re: 10035-Primary Arithmetic

Posted: Wed Jan 29, 2014 11:28 pm
by brianfry713
Post your updated code.

Re: 10035-Primary Arithmetic

Posted: Fri Jan 31, 2014 3:42 pm
by cse dipto
thnks @brianfry713 i got ac some mistake in counting thnks thnks thnks thnk u very much @brianfry713 :) :)
thnks again

Re: 10035-Primary Arithmetic

Posted: Sun Mar 09, 2014 12:15 am
by TLEorWA
AC

Re: 10035-Primary Arithmetic

Posted: Mon Mar 10, 2014 8:12 pm
by brianfry713
Try input:
809 111
0 0

Re: 10035-Primary Arithmetic

Posted: Mon Mar 10, 2014 8:42 pm
by TLEorWA
still WA.... :( @brianfry713
Here is my updated code..



why!

Re: 10035-Primary Arithmetic

Posted: Tue Mar 11, 2014 9:31 pm
by brianfry713
Try input:
90 90
0 0

Re: 10035-Primary Arithmetic

Posted: Tue Mar 11, 2014 11:46 pm
by TLEorWA
thnx brianfry713 :) AC