0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 22:08:47 +00:00
OI-codes/utils/int128.h

35 lines
581 B
C
Raw Normal View History

2021-07-10 02:37:49 +00:00
#include <algorithm>
#include <ostream>
#include <string>
2023-02-22 08:26:40 +00:00
/**
* Prints an 128-bit integer to an output stream.
*/
2021-07-10 02:37:49 +00:00
std::ostream& operator<<(std::ostream& __ostream, __int128 __n) {
std::string __o;
2023-02-22 08:26:40 +00:00
if (__n == 0) {
return __ostream << 0;
}
bool is_negative = false;
if (__n < 0) {
is_negative = true;
__n = -__n;
}
2021-07-10 02:37:49 +00:00
while (__n) {
__o.push_back(__n % 10 + '0');
__n /= 10;
}
2023-02-22 08:26:40 +00:00
2021-07-10 02:37:49 +00:00
std::reverse(__o.begin(), __o.end());
2023-02-22 08:26:40 +00:00
if (is_negative) {
__ostream << '-';
}
2021-07-10 02:37:49 +00:00
return __ostream << __o;
}