Page 2 of 12
Posted: Sat Sep 28, 2002 5:10 pm
by arnsfelt
you get integer overflow
10055
Posted: Sun Nov 10, 2002 5:39 am
by Hackson
Although I have seen all the threads about 10055, I still cannot figure out the problem it is.
[pascal]
var
a,b:longint;
begin
while not eof do
begin
readln(a,b);
if a>b then writeln(a-b)
else writeln(b-a)
end
end.
[/pascal]
Can anyone slove my problem? Thanks.
Posted: Sun Nov 10, 2002 6:59 am
by junjieliang
The input numbers are not greater than 2^32
Longint only gives you numbers up to 2^31-1,
Cardinal only gives you up to 2^32-1
So...

Posted: Sun Nov 10, 2002 1:26 pm
by haaaz
so....
Use real!
reply
Posted: Sun Nov 10, 2002 1:42 pm
by Hackson
But... Turbo Pascal doesn't have Cardinal.
Can anyone teach me how to use this type?
...Use real?
Yeah Man AC!
Posted: Sun Nov 10, 2002 1:46 pm
by Hackson
I can solve that by using real!
Thanks For help!
Question
Posted: Sat Nov 16, 2002 12:39 pm
by Ming Han
I tried the input 4294967296 0
and it returned 4294967296.
I tested with the GNU G++ and Dev C++ compiler and it worked fine.
However, I got WA...
[cpp]
// ACM Problem 10055
// Hashmat the brave warrior
// Done by Teh Ming Han
#include <iostream.h>
using namespace std;
int main(){
while (!cin.eof()){
unsigned long long int i=0,j=0,ch=0;
cin>>i>>j;
if (i>j)ch = i-j;
else ch=j-i;
cout<<ch<<endl;
}
return 0;
}[/cpp]
SO WHY DO I GET WRONG ANSWER?
Posted: Sat Nov 16, 2002 2:25 pm
by haaaz
Why don't you guys simply use double?
Hello
Posted: Sun Nov 17, 2002 8:30 am
by Ming Han
Are you sure you did not get WA for using double?
And did you read the question carefully?
Ming Han
Accepted
Posted: Wed Nov 20, 2002 4:00 pm
by Ming Han
Ok. I finally got accepted for this question.
For those who got WA, here are some good hints:
1. use long long data type.
2. create your own abs() function.
Happy programmmng.
Ming Han
Posted: Thu Nov 21, 2002 2:15 pm
by ezra
Try to use float data type. [/c]
Posted: Thu Nov 21, 2002 7:53 pm
by Larry
long long should do.
10055 Time Limit Exceeded
Posted: Thu Dec 19, 2002 4:43 am
by raysa
Hi guys! I got a Time Limit Exceeded the last I posted this code for p10055. Any idea why it happened ???
[cpp]---CODE WAS CUT---[/cpp]
Posted: Thu Dec 19, 2002 9:19 am
by Dominik Michniewski
try
Code: Select all
while(scanf("%ld %ld",&a,&b) != 2)
instead of
Code: Select all
while(scanf("%ld %ld",&a,&b) != EOF)
Best regards
Dominik
Posted: Thu Dec 19, 2002 2:38 pm
by Larry
I think Dominik means this:
Code: Select all
while(scanf("%ld %ld",&a,&b) == 2)