zoukankan      html  css  js  c++  java
  • iostream重载__int128

    Normal (Naive)写法,用 string(char* )

    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 *************/
    

    我突然有个大胆的想法系列

    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;
    }
    
  • 相关阅读:
    Callable+Future
    采用socket传输文件
    大端序和小端序
    域名
    mycat实现读写分离
    mysql存储过程
    Mysql主从同步
    centos6.5上安装5.7版本的mysql
    Mycat分库分表
    通过队列实现进程间的通信
  • 原文地址:https://www.cnblogs.com/Forgenvueory/p/7725116.html
Copyright © 2011-2022 走看看