Page 1 of 22
10035
Posted: Sat Jun 15, 2002 5:37 am
by koniloni
What is wrong with my problem?I have gotten "wrong answer".This is my code:
#include<stdio.h>
int main()
{
unsigned long x,y,a,b,c,d;
while((scanf("%ld%ld",&x,&y)==2)&&(x!=0 && y!=0))
{
if(x<=999999999 &&y<=999999999)
{
d=0,c=0;
while(x!=0 && y!=0)
{
a=x%10;
b=y%10;
x=x/10;
y=y/10;
if(a+b+d>=10)
{
++c;
d=1;
}
}
if(c==0)
printf("No carry operation\n");
else if(c==1)
printf("1 carry operation\n");
else
printf("%d carry operations\n",c);
}
}
return 0;
}
/*" @END_OF_SOURCE_CODE"*/
Posted: Sat Jun 15, 2002 8:34 am
by 10153EN
I have obverse one minor mistake, just a MINOR one, but I donno if it lead to your WA.
Please check your outputs with the sample ones.
help me
Posted: Sat Aug 31, 2002 12:33 am
by Shahid
hi, i did this program, but getting WA. i think this is quite an easy problem...and my code is ok. can anyone help me? here is my code:
[c]
/*@BEGIN_OF_SOURCE_CODE*/
#include<stdio.h>
void main()
{
int count, ad = 0, ag = 0, carry, sum = 0;
unsigned long adnd, agnd, tmp;
for(;;)
{
scanf("%lu %lu", &adnd, &agnd);
if(!adnd && !agnd)
break;
count = 0;
carry = 0;
if(adnd < agnd)
{
tmp = adnd;
adnd = agnd;
agnd = tmp;
}
while(adnd)
{
ad = adnd % 10;
ag = agnd % 10;
sum = ad + ag + carry;
if(sum > 9)
{
count++;
carry = sum / 10;
}
adnd /= 10;
agnd /= 10;
}
if(!count)
printf("No carry operation.\n");
else if(count == 1)
printf("1 carry operation.\n");
else
printf("%d carry operations.\n", count);
}
}
/*@END_OF_SOURCE_CODE*/
[/c]
10035 WR ? why?
Posted: Sat Aug 31, 2002 5:19 pm
by galois_godel
It's a easy problem. But I can't get AC.
Who can tell me why?
program a10035;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
a,b,i,c,temp:integer;
m,n:array[1..10]of integer;
lm,ln,l,carry:integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
{assign(input,'a10035.in.txt');
assign(output,'a10035.out.txt');
reset(input);
rewrite(output);}
while not eof(input) do
begin
readln(a,b);
if (a=0)and(b=0)then exit;
lm:=0;
while a<>0 do
begin
lm:=lm+1;
m[lm]:=a mod 10;
a:=a div 10;
end;
ln:=0;
while b<>0 do
begin
ln:=ln+1;
n[ln]:=b mod 10;
b:=b div 10;
end;
if ln<lm then l:=ln
else
l:=lm;
c:=0;
carry:=0;
for i:=1 to l do
begin
temp:=c+m+n;
if temp>9 then
carry:=carry+1;
c:=(m+n)div 10;
end;
if carry=0 then
writeln('No carry operation.')
else
writeln(carry,' carry operations.');
end;
{close(input);
close(output);}
end.
Posted: Sun Sep 01, 2002 9:59 am
by rakeb
if u get one carry operation the u have to print "1 carry operation." , not - "1 carry operation
S."

. i think this is ur mistake
thanx
Posted: Mon Sep 09, 2002 10:49 pm
by Shahid
hi thanx....for ur clue...
i got accepted....

10035
Posted: Thu Sep 12, 2002 4:38 pm
by Eric
It should be a easy program, however, I got wrong answer. What goes wrong?
Posted: Thu Sep 12, 2002 4:53 pm
by arc16
i think there is an input with one of the number is 0, which your program does not handle...
give it a try

P 10035
Posted: Mon Dec 23, 2002 8:03 am
by Red Scorpion
You should notice that "each line of input contains two unsigned integer less than 10 digits".
You cannot use a long integer to sum that numbers, try to use string!
Posted: Wed Jan 01, 2003 1:18 pm
by Astrakan
Using long int works fine, since the sum of two 9-digit numbers is less than 2000000000 which fits in a long int, and in this case the sum is not even calculated.
There is another error error in the program.
Try the case
The answer should be 2, not 3.
Posted: Tue Jan 21, 2003 4:59 am
by TWEmp
Astrakan wrote:Using long int works fine, since the sum of two 9-digit numbers is less than 2000000000 which fits in a long int, and in this case the sum is not even calculated.
So does that explains why my program gets a WA either?
int main() {
int a, b, c;
int i, count, carry;
do {
scanf("%d %d", &a, &b);
if (((a > 0 && b >= 0) || (a >= 0 && b > 0)) && (a < 1000000000 && b < 1000000000)) {
i = 1;
count = 0;
carry = 0;
while (a / i >= 1 || b / i >= 1) {
i *= 10;
c = (a % i) * 10 / i + (b % i) * 10 / i + carry;
if (c >= 10) count++;
carry = c / 10;
}
switch (count) {
case 0:
printf("No carry operation.\n");
break;
case 1:
printf("1 carry operation.\n");
break;
default:
printf("%d carry operations.\n", count);
}
}
} while (a != 0 || b != 0);
return 0;
}
Posted: Tue Jan 21, 2003 11:11 am
by Astrakan
TWEmp, try this case, which your program doesn't handle correctly:
The sum of two 9-digit numbers fits in a long int, but the product of a 9-digit number and 10 does not always fit.
10035
Posted: Wed Jan 22, 2003 9:27 pm
by thechaoshacker
I am getting a WA for this one. Can't figure out where I went wrong. Could somebody help me please ?
[cpp]#include<iostream.h>
unsigned long long a,b;
int main()
{
int dig1,dig2,carry=0,sum,count=0;
while(1)
{
cin>>a>>b;
if(!a&&!b)
break;
count=0;
carry=0;
while(a||b)
{
dig1=a%10;
dig2=b%10;
sum=dig1+dig2+carry;
if(sum>=10)
{
carry=1;
count++;
}
else
carry=0;
a/=10;
b/=10;
}
if(0==count)
cout<<"No carry operation.\n";
else
{
if(1==count)
cout<<"1 carry operation.\n";
cout<<count<<" carry operations.\n";
}
}
return 0;
}
[/cpp]
thanx,
thechaoshacker
Posted: Wed Jan 22, 2003 11:02 pm
by Astrakan
Try a case which gives one carry operation, for example
Stupid Mistake
Posted: Thu Jan 23, 2003 2:05 pm
by thechaoshacker
I forgot the else condition for
if(1==count)
cout<<"1 carry operation.\n";
else
cout<<count<<" carry operations.\n";
oops

thechaoshacker }