0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 14:58:48 +00:00

fix: int128 ostream helper

This commit is contained in:
Baoshuo Ren 2023-02-22 16:26:40 +08:00
parent e4083fecd7
commit 10060efd25
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -2,12 +2,33 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
/**
* Prints an 128-bit integer to an output stream.
*/
std::ostream& operator<<(std::ostream& __ostream, __int128 __n) { std::ostream& operator<<(std::ostream& __ostream, __int128 __n) {
std::string __o; std::string __o;
if (__n == 0) {
return __ostream << 0;
}
bool is_negative = false;
if (__n < 0) {
is_negative = true;
__n = -__n;
}
while (__n) { while (__n) {
__o.push_back(__n % 10 + '0'); __o.push_back(__n % 10 + '0');
__n /= 10; __n /= 10;
} }
std::reverse(__o.begin(), __o.end()); std::reverse(__o.begin(), __o.end());
if (is_negative) {
__ostream << '-';
}
return __ostream << __o; return __ostream << __o;
} }