mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:48:48 +00:00
fix: int128 ostream helper
This commit is contained in:
parent
e4083fecd7
commit
10060efd25
@ -2,12 +2,33 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* Prints an 128-bit integer to an output stream.
|
||||
*/
|
||||
std::ostream& operator<<(std::ostream& __ostream, __int128 __n) {
|
||||
std::string __o;
|
||||
|
||||
if (__n == 0) {
|
||||
return __ostream << 0;
|
||||
}
|
||||
|
||||
bool is_negative = false;
|
||||
|
||||
if (__n < 0) {
|
||||
is_negative = true;
|
||||
__n = -__n;
|
||||
}
|
||||
|
||||
while (__n) {
|
||||
__o.push_back(__n % 10 + '0');
|
||||
__n /= 10;
|
||||
}
|
||||
|
||||
std::reverse(__o.begin(), __o.end());
|
||||
|
||||
if (is_negative) {
|
||||
__ostream << '-';
|
||||
}
|
||||
|
||||
return __ostream << __o;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user