Hi all,
I have some problems with outputting long double.
Here is my code for Yandex Round 1 Problem C Petya and Tree:
http://pastebin.com/sHKuXg15
I submitted this code but got WA for testcase 1, even though it worked on my com. In the end, I realised that I cannot printf long doubles (something similar to printf long long int?), so I changed to cout. However, in that case it seems that I started to output integers :(. All my decimals places got cut off. Can someone help me?
I have some problems with outputting long double.
Here is my code for Yandex Round 1 Problem C Petya and Tree:
http://pastebin.com/sHKuXg15
I submitted this code but got WA for testcase 1, even though it worked on my com. In the end, I realised that I cannot printf long doubles (something similar to printf long long int?), so I changed to cout. However, in that case it seems that I started to output integers :(. All my decimals places got cut off. Can someone help me?
printf("%.9lf\n",double(AVG[A[P]]));
Probably there is no way to output long doubles.
UPD:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long double d = 0.12345678910;
cout << fixed;
cout << setprecision(12) << d;
return 0;
}
Run this code here with GNU and with MS compiler and see the difference.
GNU:
Comparing d & ld: 0
Comparing d & d: 1
0.00000000000000001851275209518998800000000000000000
MS:
Comparing d & ld: 1
Comparing d & d: 1
0.00000000000000000000000000000000000000000000000000
#include <cstdio>
int main()
{
long double d = 1;
printf("%Lf",d);
return 0;
}
It outputs
0.000000
MS compiler outputs 1.0... just because there is no difference between double and long double.
What GCC do you use???
Please, read "man 3 printf":
"L - A following a, A, e, E, f, F, g, or G conversion corresponds to a long double argument. (C99 allows %LF, but SUSv2 does not.)"
So...I run that in a custom test on codeforces.
Codeforces use gcc throw *ss, so... :)
#include <iomanip>
using namespace std;
int main()
{
long double d = 0.12345678910;
cout << fixed;
cout << setprecision(12) << d;
return 0;
}
=====
0.123456789100
YARLY. :-)
You can check:
will print:
May I know what is the difference between a MS compiler and GNU compiler?