Блог пользователя simp1eton

Автор simp1eton, 15 лет назад, По-английски
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?
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

15 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I think there is no real need in accuracy, so you may cast your long double to a double.

        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;
}

15 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится -14 Проголосовать: не нравится

As far as I know, in C++ long double have the same precision as double.
15 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится
As far as I know, in C++ long double have the same precision as double.
15 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

ignore
15 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
long double x;
......

printf("%Lf", x);
15 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
You may use specifier Lg for long double:

long double x;
...
printf("%Lg",x);
with GNU C++
15 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Similar question but about Java.
How to output doubles?
It seems that out.printf("%.10f", number); outputs float, not double, but format string "%.10lf" doesn't work.
15 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Thanks everyone!

May I know what is the difference between a MS compiler and GNU compiler?