## 713 - Adding Reversed Numbers

Moderator: Board moderators

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Contact:
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

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
thanks,but none of them can proove my code is wrong.it's so weird
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Contact:
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

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

### 713

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.

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:
10^500 is enough

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Contact:
Dear Sohel, I think you should use string instead of long.

Dreamer#1
Learning poster
Posts: 77
Joined: Tue Oct 07, 2003 10:07 pm
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.
Not all of our dreams can be made to come true. But still we live with the hope to turn them into reality someday.

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
Thanks so much,i'll try to solve it
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

pavelph
Learning poster
Posts: 57
Joined: Wed Dec 10, 2003 7:32 pm
Location: Russia, Saint-Petersburg
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.

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
hey,I think the number must be giant.

[cpp]
#include "iostream.h"
#include "string.h"
int main(int argc, char* argv[])
{
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;
}

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

for(loop=0;loop<strlen(b);loop++)
{
}
{
{

loop++;
}
{
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?:(
Last edited by Morning on Fri Jan 30, 2004 9:31 pm, edited 1 time in total.
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
i still got WA:(
[cpp]
#include "iostream.h"
#include "string.h"
int main(int argc, char* argv[])
{
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];
}

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

for(loop=0;loop<strlen(b);loop++)
{
}
{
{

loop++;
}
{
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]
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Contact:
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
Wisdom is know what to do next; virtue is doing it.

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
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:(
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

Learning poster
Posts: 73
Joined: Mon Oct 14, 2002 7:15 am
Location: United States
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...

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm