10035  Primary Arithmetic
Moderator: Board moderators
Re: WA 10035
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.
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.
I get WA too
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=maxmin;
while(max>min)
n2[max]=n2[maxdiff];
max = l1;
n2[max]=0x00;
for(i=0;i<diff;i++)
n2='0';
}
else
{
max=l2;
min=l1;
diff=maxmin;
while(max>min)
n1[max]=n1[maxdiff];
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]
[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=maxmin;
while(max>min)
n2[max]=n2[maxdiff];
max = l1;
n2[max]=0x00;
for(i=0;i<diff;i++)
n2='0';
}
else
{
max=l2;
min=l1;
diff=maxmin;
while(max>min)
n1[max]=n1[maxdiff];
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...
Nevermind... I worked it a different way, without all the strings and stuff. Got accepted.
Um
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.

 Learning poster
 Posts: 93
 Joined: Sun Jan 12, 2003 3:30 pm
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 ;
}
hello almost human.....
based on your code you cannot handle input like this.
output should be
Just a little mistake.
based on your code you cannot handle input like this.
Code: Select all
12300 78900
Code: Select all
2 carry operations.
Why i got WA
here is my code:
[cpp][/cpp]
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");
}
}
}
We are SKARBAN.
We will make another world.
We will make another world.
10035
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
thank you.
i'm waiting for your replies.
best regards,
awik
Last edited by awik_10 on Mon May 19, 2003 9:17 am, edited 1 time in total.
Layout problem again......
1. Line 106 should be removed.
2. Pay EXTRA attention to the output format......
[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.
1. Line 106 should be removed.
2. Pay EXTRA attention to the output format......
Correct answer:123 456
0 0
Relevent line in your code:No carry operation.
[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.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Have you done that also?Observer wrote:1. Line 106 should be removed.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org