## 10055 - Hashmat the Brave Warrior

Moderator: Board moderators

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

### Re: 10055 - Can't understand why WA

coolzero wrote: Input:
10 12
10 14
100 200
12 10

Output:
2
4
100
2

Can anyone help?

Tanks

Code: Select all

``````0 4294967296
2 4294967296
0 4294967295
2 4294967295
``````
Ciao!!!

Claudio

coolzero
New poster
Posts: 8
Joined: Fri Nov 12, 2004 11:33 am
long long int or double

Tanks

Niaz
Learning poster
Posts: 77
Joined: Fri Dec 17, 2004 11:06 am
Location: East West University, Dhaka, Bangladesh
Contact:
This is one of the easiest problems of this Archive. But still there are some tricks. To solve this problem you need to use Double (I used Long Double) and you mustn't use the built in fabs(). Write this function for your code manually and then there will be nothing to stop you from getting accepted
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/

59557RC
New poster
Posts: 26
Joined: Sun Mar 20, 2005 9:28 pm
Contact:

### 10055-ll i ever get rid from PE

i got PE from about 50% of my AC problems.can anyone pls tell me why i got PE for this:
#include<stdio.h>
#include<math.h>

int main(void)
{
double a1,a2;
while(scanf("%lf %lf",&a1,&a2)!=EOF) printf("\n%.0lf\n",fabs(a1-a2));
return 0;
}
aaa

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

### Re: 10055-ll i ever get rid from PE

59557RC wrote:i got PE from about 50% of my AC problems.can anyone pls tell me why i got PE for this:
#include<stdio.h>
#include<math.h>

int main(void)
{
double a1,a2;
while(scanf("%lf %lf",&a1,&a2)!=EOF) printf("\n%.0lf\n",fabs(a1-a2));
return 0;
}
Well, you print a redundant newline at the beginning of output...

Ciao!!!

Claudio

59557RC
New poster
Posts: 26
Joined: Sun Mar 20, 2005 9:28 pm
Contact:

### yeah!!

ya i got AC.thanx
aaa

New poster
Posts: 7
Joined: Sat May 07, 2005 5:20 am

### 10055 C++ WA

#include <iomanip.h>
#include <iostream.h>

int main ()
{
long double hashmat, other, difference;

while(cin >> hashmat >> other)
{
difference = hashmat - other;

if(difference < 0)
cout << (difference * -1) << endl;
else
cout << difference << endl;
}
}

The program works for all the Sample Data. I think I'm running into the problem of input terminating on End of File. Call me a moron, but I'm not sure how I should test for that? Also, when I test with large numbers, my output comes out in scientific notation

Input:
100000000 1

Output:
1e+08

I tried using the "fixed" function for the output in another problem I'm working on, but I get a compile error when OJ tries to use it. Any help would be great!

Thanks

dumb dan
Learning poster
Posts: 67
Joined: Tue Aug 05, 2003 1:02 am
Your current method for reading input should works perfectly ok. When your program is tested by the judge, your program recieves a file from standard input. This is perfectly normal and you don't need to think about that. Basically what they mean is that you should read input as long as there is more input to read. But you could also check for an EOF-character if you read input character by character.

As for avoiding scientific notation, the easiest way would be to use long long integers instead of long doubles. Or if you insist on long doubles, at least make a type conversion before you print them.

n00i3
New poster
Posts: 20
Joined: Thu Sep 15, 2005 8:49 pm
Contact:
hey qbens, I think that you check for the validity of cin i.e. !cin.eof() before you even input anything from the input stream ... i.e. cin>>

Maybe thats why it fails?

tmdrbs6584
Learning poster
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)

### long long int

printf("%lld\n", abs(n2-n1));
This is correct.

tmdrbs6584
Learning poster
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)

### input & output

input
1 10
100 1000
10000 100000
output
9
900
90000

And you must use long long int

tmdrbs6584
Learning poster
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)
abs(versa - hashmat)

Carunty
New poster
Posts: 18
Joined: Sat Jul 08, 2006 2:40 am

### 10055 CE

I dont know why i get compile error.
Can anyone tell me what is wrong?

#include <iostream>
#include <cmath>
using namespace std;

int main(){
long long x,y;
while(cin >> x >> y) cout << abs(x-y) << endl;
}

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm
i think change your abs() Built In function.
OK just make your own one. May be judge change their Compiler.
Actually i dont think its GOOD. They might be announced it.

Sometimes you also get CE for #include <memory>
so change it also #include <cstring>.

hope it helps.[/code]

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore