Excuse me, can anyone tell me how to use printf
to output long double
values?
I tried to use %Lf
, but it just output zero when I chose GNU C++11
.
However, I got AC when choosing GNU C++17 (64)
.
Can anyone tell me what should I do? Thank you~
GNU C++11
submission (WA on 1): https://codeforces.me/contest/1209/submission/92331960
GNU C++17 (64)
submission (AC): https://codeforces.me/contest/1209/submission/92331832
Just use
GNU C++17 (64)
If you're down with cout then,
This worked -> Here
It still doesn't work with
GNU C++11
.I have used simple
cout
in your code with both C++14 and C++11 with outputs 361.569 and 1000 respectively.Now I don't think this is possible unless you've used something else that is broken in C++11. I might be wrong.
Only using
std::cin & std::cout
instead ofscanf & printf
can it work withGNU C++11
.A tangential answer: note that, most of the time, casting to a
double
would be fine in output, as a relative error of $$$10^{-9}$$$ is allowed.well, it's quite complicated.
Huh? How much more complicated is
printf ("%.6lf", (double) (x));
?Instead of just
printf ("%.6Lf", x);
.I also need to use
instead of
Yeah, that, too. But reading and writing values is an easy part of the problem. Usually.
You're right.
Short answer is, you don't. The implementation used by codeforces's version of C++11 does not implement printf for long doubles.
You can switch to the mingw implementation by either submitting in C++11 with
#define __USE_MINGW_ANSI_STDIO 1
before your code, or by submitting in C++17 (64). Be aware though that mingw printf is slow so you are exposing yourself to potential TLEs by doing this.To be safe, I would either switch to using cout and a more recent version of C++, or use C++11 printf after casting to double.
Thanks a lot.
Where do you get your backgrounds? I need to know.
Pixiv, a Japanese online community for artists.
ah ok, I thought you had some nice collection since yours all look similar.
yeah~ XD
oh god it does support margins...