10055 - Hashmat the Brave Warrior

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

arnsfelt
New poster
Posts: 44
Joined: Wed Oct 17, 2001 2:00 am
Location: Denmark
Contact:

Post by arnsfelt »

you get integer overflow
Hackson
New poster
Posts: 35
Joined: Sun Nov 10, 2002 5:36 am

10055

Post 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.
junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post 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...:D
haaaz
New poster
Posts: 29
Joined: Sun Sep 08, 2002 8:02 am

Post by haaaz »

so.... :D
Use real!
Hackson
New poster
Posts: 35
Joined: Sun Nov 10, 2002 5:36 am

reply

Post by Hackson »

But... Turbo Pascal doesn't have Cardinal.
Can anyone teach me how to use this type?

...Use real?
Hackson
New poster
Posts: 35
Joined: Sun Nov 10, 2002 5:36 am

Yeah Man AC!

Post by Hackson »

I can solve that by using real!
Thanks For help!
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Question

Post 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?
:: HanWorks ::
haaaz
New poster
Posts: 29
Joined: Sun Sep 08, 2002 8:02 am

Post by haaaz »

Why don't you guys simply use double?
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Hello

Post by Ming Han »

Are you sure you did not get WA for using double?
And did you read the question carefully?

Ming Han
:: HanWorks ::
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Accepted

Post 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
:: HanWorks ::
User avatar
ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm

Post by ezra »

Try to use float data type. [/c]
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

long long should do.
raysa
New poster
Posts: 40
Joined: Wed Dec 18, 2002 4:23 pm
Location: Indonesia

10055 Time Limit Exceeded

Post 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]
Last edited by raysa on Wed Apr 09, 2003 8:56 am, edited 3 times in total.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post 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
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

I think Dominik means this:

Code: Select all

while(scanf("%ld %ld",&a,&b) == 2)
Post Reply

Return to “Volume 100 (10000-10099)”