Page 2 of 22

Re: WA 10035

Posted: Tue Jan 28, 2003 1:19 pm
by route
I didn't test your program..
but here's my suggestion that one can easily get wrong

999
1
4 carry operations.

or to increase the array of char

or when the length of the second number is greater than that of the first number.

Check if u a correct.

Posted: Wed Feb 05, 2003 10:24 am
by turuthok
Looks like you don't clear up your arrays before any addition ... eventhough your solution survives the first test-case, it's hard to believe it would pass subsequent cases ... try this test cases:

91 2
1 12
0 0

Both test-cases doesn't have carry operations ...

-turuthok-

I get WA too

Posted: Tue Mar 25, 2003 4:32 pm
by Derk
I've tried every sample input, every input in all the threads here. I try max and mins, and all kings of different values in between and I still can't get accepted. It runs for a little bit before it gets WA, so I'm doing something right...

[c]/* @JUDGE_ID: xxxxxx 10035 C*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUFFERSIZE 30

main()
{
char buffer[BUFFERSIZE], n1[12], n2[12];
int carries, c, l1, l2,max,min,i,diff,a,b;
#ifndef ONLINE_JUDGE
close (0); open ("10035.in", O_RDONLY);
close (1); open ("10035.out", O_WRONLY | O_CREAT, 0600);
#endif

while(1)
{
gets(buffer);

sscanf(buffer,"%d %d",&a,&b);

if (a==0 && b==0 && strlen(buffer)<4)
return;

sprintf(n1, "%d",a);
sprintf(n2, "%d",b);

l1 = strlen(n1);
l2 = strlen(n2);

carries=0;
c=0;

if (l1>l2)
{
max=l1;
min=l2;
diff=max-min;

while(max-->min)
n2[max]=n2[max-diff];
max = l1;
n2[max]=0x00;
for(i=0;i<diff;i++)
n2='0';
}
else
{
max=l2;
min=l1;
diff=max-min;

while(max-->min)
n1[max]=n1[max-diff];
max = l2;
n1[max]=0x00;

for(i=0;i<diff;i++)
n1='0';
}


while (max>0)
{
max--;
if (c+n1[max]-'0'+n2[max]-'0'>9)
{
c=1;
carries++;
}
else
c=0;
}

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

}

}

/* @END_OF_SOURCE_CODE */[/c]

Nevermind...

Posted: Tue Mar 25, 2003 6:46 pm
by Derk
Nevermind... I worked it a different way, without all the strings and stuff. Got accepted.

Posted: Wed Mar 26, 2003 1:48 pm
by Eric
I get AC. Thx~

Posted: Tue Apr 08, 2003 1:28 am
by SoLtRiX
there are no need to use strings. i use unsigned long long int and i've got AC.

be carefull width inputs width only one zero
123 0
0 2

Um

Posted: Tue Apr 08, 2003 1:04 pm
by Derk
as I said already, nevermind, I got AC. Also, you can't use unsigned long long ints in C. Different programming language. Also, you don't even need that -- a simple int will suffice. Anything else is overkill.

Posted: Fri Apr 25, 2003 1:25 pm
by Almost Human
I got problem too... please help me ... I still got WA

Code: Select all

#include <stdio.h>

int main ( )
{
	unsigned long operand1 , operand2 , result ;
	int carry , carryflag ;

	freopen ( "10035.in" , "r" , stdin ) ;
	freopen ( "10035.out" , "w" , stdout ) ;

	while ( 1 )
	{
	 scanf ( "%lu %lu" , &operand1 , &operand2 ) ;

	 if ( !operand1 && !operand2 ) break ;

	 carryflag = carry = 0 ;

	 do
	 {
		 if ( carryflag ) carry ++ ;

		 result = ( operand1 % 10 ) + ( operand2 % 10 ) + carryflag ;
		 operand1 /= 10 ; operand2 /= 10 ;

		 carryflag = result / 10 ;
	 }
	 while ( result ) ;

	 if ( !carry )
		 printf ( "No " ) ;
	 else
		 printf ( "%i " , carry ) ;
	 printf ( "carry operation" ) ;

	 if ( carry > 1 ) printf ( "s.\n" ) ;
	 else printf ( ".\n" ) ;
	}

	return 0 ;
}

Posted: Fri Apr 25, 2003 2:07 pm
by Hisoka
hello almost human.....

based on your code you cannot handle input like this.

Code: Select all

12300 78900
output should be

Code: Select all

2 carry operations.
Just a little mistake. :wink:

Posted: Wed May 07, 2003 1:09 pm
by rumel_new
Why i got WA
here is my code:
[cpp]

Code: Select all

#include<stdio.h>
#include<stdlib.h>
void main ()
{
unsigned long x,y;
unsigned long carry,temp_carry,temp_x,temp_y;	
while(2 == scanf("%lu %lu",&x,&y))
{
if((x == 0) && (y == 0))
break;
else
{
carry =0;
temp_carry = 0;
while(x)
{
temp_x = x%10;
x = x / 10;
temp_y = y%10;
y = y / 10;
temp_carry = (temp_carry + temp_x + temp_y) /10;
if(temp_carry>0)
carry++;
}
if(carry == 1)
printf("1 carry operation.\n");
else if(carry > 1)
printf("%lu carry operations.\n",carry);
else
printf("No carry operation.\n");
}
}
}
[/cpp]

10035

Posted: Sun May 18, 2003 3:53 pm
by awik_10
can you tell me what's my wrong? i've tried some exceptions like 988+15-->3 carry operations, 188+15--> 2 carry operations, and the other one is 100+0--> No carry operation. tell me if there's something wrong :( .

thank you.
i'm waiting for your replies.
best regards,
awik

Posted: Sun May 18, 2003 4:15 pm
by Observer
Layout problem again...... :P

1. Line 106 should be removed.
2. Pay EXTRA attention to the output format......
123 456
0 0
Correct answer:
No carry operation.
Relevent line in your code:
[c] if(ctr==0) printf("No carry operation\n"); [/c]


******* Think ***********************
************ Think ******************
***************** Think *************





P.S. Again, after some minor amendment, I got an ACC with your code.

Posted: Mon May 19, 2003 8:37 am
by awik_10
ya, i've seen what's my fault is. it is because my output without a dot(.), but i've still been seen as a presentation error, not correctly at all. can you tel me the other fault, besides dot that make my program P.E.
thank you
best regards,
awik

Posted: Mon May 19, 2003 8:57 am
by Observer
Observer wrote:1. Line 106 should be removed.
Have you done that also?

Posted: Mon May 19, 2003 9:40 am
by awik_10
thank you.
awik