Page 3 of 10

Posted: Thu Jan 29, 2004 12:17 pm
by Raiyan Kamal
I got AC.

here are some sample inputs and outputs. Hope these will help you. :-)

Input:

100 200
999999999999999 1
00010 9
1 9
1 9
5 5
456 654
0 0



Output:

3
1
9001
1
1
1
111
0

Posted: Thu Jan 29, 2004 1:29 pm
by Morning
thanks,but none of them can proove my code is wrong.it's so weird

Posted: Thu Jan 29, 2004 2:24 pm
by Raiyan Kamal
May be there are numbers like 10^1000 or so. I used two strings of length 1000 to store the input numbers. I can't code in JAVA, so could not understand wheather you took care of that or not. Did you :-?

713

Posted: Thu Jan 29, 2004 2:58 pm
by WR
I think there's been a rejudgement yesterday, because my program
had already been accepted and now it's missing from the list of
accepted programs. Submitting it again led to a WA, so I guess
I was just lucky too.

Posted: Thu Jan 29, 2004 5:58 pm
by sjn
10^500 is enough :wink:

Posted: Thu Jan 29, 2004 7:16 pm
by Raiyan Kamal
Dear Sohel, I think you should use string instead of long.

Posted: Fri Jan 30, 2004 9:33 am
by Dreamer#1
I know its really stupid but the new input set contains numbers as big as 10^100 or larger, so, you must use string arithmetic to get through.

Hope it helps. :)

The most horrible thing is that the problem description never had any range for input so most of the old AC solutions didn't take that into account and getting WA after rejudgement. :(

Posted: Fri Jan 30, 2004 9:42 am
by Morning
Thanks so much,i'll try to solve it

Posted: Fri Jan 30, 2004 7:35 pm
by pavelph
No, I think that Sohel has problem in other way ( in my program I used array [1 .. 500] and get AC).
Sohel, maybe your program write zeros at the begin of line or at the end of it.

Posted: Fri Jan 30, 2004 7:51 pm
by Morning
hey,I think the number must be giant.

[cpp]
#include "iostream.h"
#include "string.h"
int main(int argc, char* argv[])
{
unsigned int ifAdd,loop,i;
char a[10000],b[10000],temp[10000];
while(cin>>a>>b)
{
if(a[0]==b[0] && b[0]=='0' && b[1]=='\0') cout<<'0'<<endl;
else
{
for(loop=0;loop<strlen(a);loop++)
{
while(a[loop]=='0')
for(i=loop;i<strlen(a);i++)
a=a[i+1];
break;
}
for(loop=0;loop<strlen(b);loop++)
{
while(b[loop]=='0')
for(i=loop;i<strlen(b);i++)
b=b[i+1];
break;
}


ifAdd=0;
if(strlen(a)<strlen(b))
{
strcpy(temp,a);
strcpy(a,b);
strcpy(b,temp);
}
strcpy(temp,a);

for(loop=0;loop<strlen(b);loop++)
{
temp[loop]=(a[loop]+b[loop]+ifAdd-96)%10+48;
if(a[loop]+b[loop]-96>9) ifAdd=1;
else ifAdd=0;
}
if(ifAdd!=0)
{
while(ifAdd!=0 && loop<strlen(a))
{
temp[loop]=(a[loop]+ifAdd-48)%10+48;

if(temp[loop]+1<10) ifAdd=0;
loop++;
}
if(ifAdd!=0 && loop==strlen(a))
{
temp[loop]=49;
temp[loop+1]='\0';
}
}
for(loop=strlen(temp)-1;loop>0;loop--)
{
if(temp[loop]=='0')
{
temp[loop]='\0';
}
else break;
}
for(loop=0;loop<strlen(temp);loop++)
if(temp[loop]!='0') break;
for(;loop<strlen(temp);loop++) cout<<temp[loop];
cout<<endl;
}
}
return 0;
}
[/cpp]
at first i defined my array as large as 100;and got RE,then i changed it into 10000,then got WA.who can tell me where's the problem?:(

Posted: Fri Jan 30, 2004 7:52 pm
by Morning
i still got WA:(
[cpp]
#include "iostream.h"
#include "string.h"
int main(int argc, char* argv[])
{
unsigned int ifAdd,loop,i;
char a[10000],b[10000],temp[10000];
while(cin>>a>>b)
{
if(a[0]==b[0] && b[0]=='0' && b[1]=='\0') cout<<'0'<<endl;
else
{
for(loop=0;loop<strlen(a);loop++)
{
while(a[loop]=='0')
for(i=loop;i<strlen(a);i++)
a=a[i+1];
}
for(loop=0;loop<strlen(b);loop++)
{
while(b[loop]=='0')
for(i=loop;i<strlen(b);i++)
b=b[i+1];
}


ifAdd=0;
if(strlen(a)<strlen(b))
{
strcpy(temp,a);
strcpy(a,b);
strcpy(b,temp);
}
strcpy(temp,a);

for(loop=0;loop<strlen(b);loop++)
{
temp[loop]=(a[loop]+b[loop]+ifAdd-96)%10+48;
if(a[loop]+b[loop]-96>9) ifAdd=1;
else ifAdd=0;
}
if(ifAdd!=0)
{
while(ifAdd!=0 && loop<strlen(a))
{
temp[loop]=(a[loop]+ifAdd-48)%10+48;

if(temp[loop]+1<10) ifAdd=0;
loop++;
}
if(ifAdd!=0 && loop==strlen(a))
{
temp[loop]=49;
temp[loop+1]='\0';
}
}
for(loop=strlen(temp)-1;loop>0;loop--)
{
if(temp[loop]=='0')
{
temp[loop]='\0';
}
else break;
}
for(loop=0;loop<strlen(temp);loop++)
if(temp[loop]!='0') break;
for(;loop<strlen(temp);loop++) cout<<temp[loop];
cout<<endl;
}
}
return 0;
}
[/cpp]

Posted: Fri Jan 30, 2004 8:29 pm
by razibcse
To Raiyan Kamal:
I got AC.

here are some sample inputs and outputs. Hope these will help you.

Input:

100 200

999999999999999 1

00010 9

1 9

1 9

5 5

456 654

0 0

Output:

3

1

9001

1

1

1

111

0
But the preoblem statement said,
Also note that the reversed number never has any trailing zeros.
So when you use 00010 and 9 as inputs, 00010 becomes 1 and the result becomes 1 rather than 9001.

And both the input numbers are positive,so there will be no zero as input.

R@zib

Posted: Fri Jan 30, 2004 8:32 pm
by Morning
first of all,thanks for ur help indeed.
i think there will be 0 0 because of ur sample input.:)
and i got the right answer to the input 0010 9,it's 1 right?
so there must be any other problem:(

Posted: Sat Jan 31, 2004 4:27 am
by rjhadley
I don't think
0010 9
is valid input. But for
10 9
the output should be
1
.

Also, it looks like the new input set might have whitespace problems since there are only 39 AC, but 802 PE...

Posted: Sat Jan 31, 2004 6:48 am
by Raiyan Kamal
In the problem destcription it has been said that there will be no trailing zero(s). So I removed all the trailing zero(s). It has been also said that all the leading zeros are omitted while reversing. But the judge usually does strange things, specially after rejudgement. So I thaught there might be input with leading zero(s). That's why I care about that --- 00010 9 --- case. I know, it is not a valid input. But, there is no line in the problem description saying that there will be no invalid input.

By the way, my AC code gives 9001 as out put for that case.

Thanks to everyone.