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

waleed.lutfi
New poster
Posts: 5
Joined: Thu Jul 19, 2012 1:02 am

Re: 10035 - Primary Arithmetic

Post by waleed.lutfi » Thu Jul 19, 2012 1:09 am

I have tried all input cases posted in this thread all of them generated correct output, but I still get WA.
Any help will be appreciated

Code: Select all

Acc thanks to  brianfry713 :D
Last edited by waleed.lutfi on Thu Jul 19, 2012 11:50 am, 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

Post by brianfry713 » Thu Jul 19, 2012 2:45 am

9 1
8 1
0 0
Check input and AC output for thousands of problems on uDebug!

goldenbird299
New poster
Posts: 5
Joined: Sun Aug 05, 2012 6:56 am

10035 - Primary Arithmetic

Post by goldenbird299 » Sun Aug 05, 2012 8:30 am

hi
this is my code for this problem, can anybody tell me why it keeps giving me WA?

Code: Select all

AC
}
Last edited by goldenbird299 on Wed Aug 15, 2012 3:21 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

Post by brianfry713 » Mon Aug 06, 2012 11:05 pm

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

goldenbird299
New poster
Posts: 5
Joined: Sun Aug 05, 2012 6:56 am

Re: 10035 - Primary Arithmetic

Post by goldenbird299 » Wed Aug 15, 2012 3:22 pm

Thanks Brianfry
i got AC
:)

aniksharif
New poster
Posts: 2
Joined: Wed Aug 29, 2012 12:35 pm

getting WA for 10035 help me

Post by aniksharif » Wed Aug 29, 2012 1:43 pm

#include<stdio.h>
#include<string.h>
int main()
{
int x,y,z,i,j,k;
char a[100],b[100],c;
while(scanf("%s %s",&a,&b)==2 && a[0]!='0' && b[0]!='0')
{
k=0;
x=strlen(a);
y=strlen(b);
for(i=x,j=y;i>=0,j>=0;i--,j--)
{
z=(a-48)+(b[j]-48);
if(z>9) k++;
}
if(k==0)
printf("No carry operation.\n");
else printf("%d carry operation.\n",k);
}
return 0;
}

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

Re: getting WA for 10035 help me

Post by brianfry713 » Wed Aug 29, 2012 11:06 pm

In the sample I/O it's "3 carry operations." not "3 carry operation.", you're missing the s at the end.
Check input and AC output for thousands of problems on uDebug!

aniksharif
New poster
Posts: 2
Joined: Wed Aug 29, 2012 12:35 pm

Re: getting WA for 10035 help me

Post by aniksharif » Wed Sep 05, 2012 9:10 am

I did what u say,but still getting wa.......
#include<stdio.h>
#include<string.h>
int main()
{
int x,y,z,i,j,k,l;
char a[100],b[100],c;
while(scanf("%s %s",&a,&b)==2 && a[0]!='0' && b[0]!='0')
{
k=0;
l=0;
x=strlen(a);
y=strlen(b);

for(i=x,j=y;j>=0,i>=0;i--,j--)
{
z=(a-48)+(b[j]-48)+l;
if(z>9)
{
l=z/10;
k++;
}
}

if(k==0)
printf("No carry operation.\n");
else if(k==1) printf("1 carry operation.\n");
else printf("%d carry operations.\n",k);
}
return 0;
}

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

Re: getting WA for 10035 help me

Post by brianfry713 » Wed Sep 05, 2012 10:26 pm

Input

Code: Select all

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

MewCatcher
New poster
Posts: 19
Joined: Tue Oct 30, 2012 8:19 am

10035 Runtime Error!!! I tried a lot and get right answer

Post by MewCatcher » Tue Oct 30, 2012 8:33 am

I know it's not a good code at all, but I just want to know the very reason... :o
Thanks everyone opening this page!~ :)
Hope the kind you can help me!~ :D

Code: Select all

#include <stdio.h>
#include <stdbool.h>
#include <string.h>

/*Sample Input:
123 456
555 555
123 594
1234 5678910
9999999999 9999999999
9999999999 1
0 0

Sample Output:
No carry operation.
3 carry operations.
1 carry operation.
2 carry operations.
10 carry operations.
10 carry operations.
*/

int main( )
{
    int i, index, S, B, length1, length2;
    char temp1[ 15 ], temp2[ 15 ];
    bool Judge1, Judge2, Flag1, Flag2;
    while( ~scanf( "%s %s", temp1, temp2 ) ) {
        index = 0;
        Judge1 = true;
        Judge2 = true;
        Flag1 = false;
        Flag2 = false;
        length1 = strlen( temp1 );
        length2 = strlen( temp2 );
        for( i = 0; i < length1; i ++ ) if( ( temp1[ i ] - 48 ) != 0 ) { Flag1 = true; break; }
        for( i = 0; i < length2; i ++ ) if( ( temp2[ i ] - 48 ) != 0 || Flag1 ) { Flag2 = true; break; }/*Avoid 000010 000000*/
        if( Flag1 == false && Flag2 == false ) break;
        S = length1 > length2 ? length2 : length1;/*Smaller*/
        B = length1 > length2 ? length1 : length2;/*Bigger*/
        for( i = 0; i < B; ) {
            if( length1 - i - 1 < 0 ) Judge1 = false;
            if( length2 - i - 1 < 0 ) Judge2 = false;
            if( Judge1 && Judge2 ) {
                if( temp1[ length1 - i - 1 ] + temp2[ length2 - i - 1 ] - 96 > 9 ) {
                    index ++;
                    i ++;
                    if( length1 - i - 1 < 0 ) Judge1 = false;
                    if( length2 - i - 1 < 0 ) Judge2 = false;
                    if( i < S - 1 ) temp1[ length1 - i - 1 ] ++;
                    else Judge1 ? temp1[ length1 - i - 1 ] ++ : temp2[ length2 - i - 1 ] ++;
                }
                else i ++;
            }
            else if( Judge1 ) {
                if( temp1[ length1 - i - 1 ] - 48 > 9 ) {
                    index ++;
                    if( i < B - 1 ) {
                        i ++;
                        temp1[ length1 - i - 1 ] ++;
                    }
                    else i ++;
                }
                else break;
            }
            else {
                if( temp2[ length2 - i - 1 ] - 48 > 9 ) {
                    index ++;
                    if( i < B - 1 ) {
                        i ++;
                        temp2[ length2 - i - 1 ] ++;
                    }
                    else i ++;
                }
                else break;
            }
        }
        if( index == 0 ) printf( "No carry operation.\n" );
        else printf( "%d carry operation%s", index, index == 1 ? ".\n" : "s.\n" );
    }
    return 0;
}


MewCatcher
New poster
Posts: 19
Joined: Tue Oct 30, 2012 8:19 am

Re: 10035 Runtime Error!!! I tried a lot and get right answe

Post by MewCatcher » Tue Oct 30, 2012 1:44 pm

Please, help me - a newbie.

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

Re: 10035 Runtime Error!!! I tried a lot and get right answe

Post by brianfry713 » Wed Oct 31, 2012 1:33 am

Change line 66 to:
else if(Judge2) {
Check input and AC output for thousands of problems on uDebug!

MewCatcher
New poster
Posts: 19
Joined: Tue Oct 30, 2012 8:19 am

Re: 10035 Runtime Error!!! I tried a lot and get right answe

Post by MewCatcher » Wed Oct 31, 2012 11:39 am

:o God! You!~
Two tiny excellent answers make perfect!~
Thank you !!! ^_^

tarsun
New poster
Posts: 7
Joined: Thu Sep 20, 2012 7:58 pm
Contact:

10035 - Primary Arithmetic

Post by tarsun » Sun Nov 04, 2012 9:15 am

Wrong Answer, Pls Help

Code: Select all

#include<stdio.h>
#include<string.h>

int main()
{
	 static  long int ar[100],br[100],i,j,sum,k,extra,cry,len1,len2,w,q;
	 char str1[100],str2[100];

	 while(scanf("%s%s",&str1,&str2)==2)
	 {
		if((str1[0]=='0')&&(str2[0]=='0'))
		   break;
		i=1;
		j=1;
		len1=strlen(str1);
		len2=strlen(str2);
		for(q=len1-1;q>=0;q--)
			ar[i++]=str1[q]-48;
		for(w=len2-1;w>=0;w--)
			br[j++]=str2[w]-48;
		i=i-1;
		j=j-1;
		sum=0;
		cry=0;
		for(k=1,extra=0;(k<=i&&k<=j);k++)
		{
		  sum=ar[k]+br[k]+extra;
	    //	  res[k]=sum%10;
		  extra=sum/10;
		 if(extra>0)
			cry=cry+1;
		}
		for(;k<=i;k++)
		{
		   sum=ar[k]+br[k]+extra;
	      //	   res[k]=sum%10;
		  extra=sum/10;
		 if(extra>0)
			cry=cry+1;


		}
		for(;k<=j;k++)
		{
		  sum=ar[k]+br[k]+extra;
		//   res[k]=sum%10;
		  extra=sum/10;
		 if(extra>0)
			cry=cry+1;


		}
	 //	if(extra!=0)
	   //	{       res[k]=extra;
	     //		k=k+1;
	     //	}
	    //	for(p=k-1;p>=1;p--)
	      //		printf("%lld",res[p]);
		if(cry==0)
			printf("No carry operation.\n");
		else if(cry==1)
			printf("%ld carry operation.\n",cry);
		else
			printf("%ld carry operations.\n",cry);
	 }
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 » Tue Nov 06, 2012 3:42 am

Try input:

Code: Select all

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

Post Reply

Return to “Volume 100 (10000-10099)”