Normal (Naive)寫法,用 string(char* )git
std::ostream& operator <<(std::ostream&out,const __int128 b) { std::string s; __int128 t = b;int sig = 1; if(t < 0) sig = -1,t = -t; for(;t;t/=10) s += '0' + t % 10; if(sig == -1) s += '-'; reverse(s.begin(), s.end()); if(s.length() == 0) s += '0'; out << s ; return out; } /********* istrream 相似讀入掛 O(∩_∩)O *************/
我忽然有個大膽的想法系列code
std::ostream& operator <<(std::ostream&out, __int128 x) { if(x < 0) {out << "-"; out << -x; return out;} if(x == 0) {out << "0"; return out;} if(x > 10) out << x / 10; out << "0123456789"[x % 10]; return out; } std::istream& operator >>(std::istream&in, __int128 &x) { char c; while(c = in.get(), c != '-' && !isdigit(c)); if(c == '-') {x = '0' - (c = in.get()); while(isdigit(c = getchar()))x = x * 10 + '0' - c;} else {x = c - '0'; while(isdigit(c = in.get()))x = x * 10 - '0' + c;}; return in; }