int128输入输出流

using i128 = __int128;

istream &operator>>(istream &is, i128 &x) {
    string s;
    is >> s;
    bool neg = false;
    x = 0;
    for (char c : s) {
        if (c == '-') neg = true;
        else x = x * 10 + (c - '0');
    }
    if (neg) x = -x;
    return is;
}

ostream &operator<<(ostream &os, i128 x) {
    if (x == 0) os << 0;
    else {
        string s, t;
        if (x < 0) x = -x, t = "-";
        while (x) s.push_back('0' + x % 10), x /= 10;
        reverse(s.begin(), s.end());
        os << t << s;
    }
    return os;
}
posted @ 2024-08-09 18:51  Ke_scholar  阅读(9)  评论(0编辑  收藏  举报