Page 5 of 12

Re: 10055 - Can't understand why WA

Posted: Thu Nov 25, 2004 10:27 am
by CDiMa
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

Posted: Thu Nov 25, 2004 10:41 am
by coolzero
long long int or double :)


Tanks

Posted: Sat Dec 18, 2004 4:28 pm
by Niaz
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 :)

10055-ll i ever get rid from PE

Posted: Wed Apr 06, 2005 1:51 pm
by 59557RC
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;
}

Re: 10055-ll i ever get rid from PE

Posted: Wed Apr 06, 2005 1:55 pm
by CDiMa
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

yeah!!

Posted: Wed Apr 06, 2005 2:12 pm
by 59557RC
ya i got AC.thanx

10055 C++ WA

Posted: Tue May 10, 2005 1:28 am
by AdamP
#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

Posted: Tue May 10, 2005 8:50 am
by dumb dan
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.

Posted: Tue Oct 04, 2005 9:34 pm
by n00i3
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? :P

long long int

Posted: Thu Feb 09, 2006 12:57 pm
by tmdrbs6584
printf("%lld\n", abs(n2-n1));
This is correct.

input & output

Posted: Thu Feb 09, 2006 12:59 pm
by tmdrbs6584
input
1 10
100 1000
10000 100000
output
9
900
90000

And you must use long long int

Posted: Thu Feb 09, 2006 1:02 pm
by tmdrbs6584
abs(versa - hashmat)

10055 CE

Posted: Fri Jul 21, 2006 7:16 am
by Carunty
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;
}

Posted: Fri Jul 21, 2006 8:00 am
by asif_rahman0
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]

Posted: Sat Jul 22, 2006 4:47 am
by chunyi81
#include <cstdlib> instead of <cmath>