struct ioss
{
  #define endl '\n'
static const int LEN = ;
char obuf[LEN], *oh = obuf;
std::streambuf *fb;
ioss()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
fb = cout.rdbuf();
}
inline char gc()
{ static char buf[LEN], *s, *t, buf2[LEN];
return (s == t) && (t = (s = buf) + fread(buf, , LEN, stdin)), s == t ? - : *s++;
}
inline ioss &operator>>(long long &x)
{
static char ch, sgn, *p;
ch = gc(), sgn = ;
for (; !isdigit(ch); ch = gc())
{
if (ch == -)
return *this;
sgn |= ch == '-';
}
for (x = ; isdigit(ch); ch = gc())
x = x * + (ch ^ '');
sgn && (x = -x);
return *this;
}
inline ioss &operator>>(int &x)
{
static char ch, sgn, *p;
ch = gc(), sgn = ;
for (; !isdigit(ch); ch = gc())
{
if (ch == -)
return *this;
sgn |= ch == '-';
}
for (x = ; isdigit(ch); ch = gc())
x = x * + (ch ^ '');
sgn && (x = -x);
return *this;
}
inline ioss &operator>>(char &x)
{
static char ch;
for (; !isalpha(ch); ch = gc())
{
if (ch == -)
return *this;
}
x = ch;
return *this;
}
inline ioss &operator>>(string &x)
{
static char ch, *p, buf2[LEN];
for (; !isalpha(ch) && !isdigit(ch); ch = gc())
if (ch == -)
return *this;
p = buf2;
for (; isalpha(ch) || isdigit(ch); ch = gc())
*p = ch, p++;
*p = '\0';
x = buf2;
return *this;
}
inline ioss &operator<<(string &c)
{
for (auto &p : c)
this->operator<<(p);
return *this;
}
inline ioss &operator<<(const char *c)
{
while (*c != '\0')
{
this->operator<<(*c);
c++;
}
return *this;
}
inline ioss &operator<<(const char &c)
{
oh == obuf + LEN ? (fb->sputn(obuf, LEN), oh = obuf) : ;
*oh++ = c;
return *this;
}
inline ioss &operator<<(int x)
{
static int buf[], cnt;
if (x < )
this->operator<<('-'), x = -x;
if (x == )
this->operator<<('');
for (cnt = ; x; x /= )
buf[++cnt] = x % | ;
while (cnt)
this->operator<<((char)buf[cnt--]);
return *this;
}
inline ioss &operator<<(long long x)
{
static int buf[], cnt;
if (x < )
this->operator<<('-'), x = -x;
if (x == )
this->operator<<('');
for (cnt = ; x; x /= )
buf[++cnt] = x % | ;
while (cnt)
this->operator<<((char)buf[cnt--]);
return *this;
}
~ioss()
{
fb->sputn(obuf, oh - obuf);
}
} io;

使用:io>>x>>y; 即可

c++ 读入优化通用模板的更多相关文章

  1. c++读入优化

    对于输入数据非常大的一些可(变)爱(态)题目,scanf就会大大拖慢程序的运行速度,cin就更不用说了,所以我们要用一种高大上的东西——读入优化. 读入优化的原理其实就是一个一个字符的读入,再组成数字 ...

  2. c++ 读入优化、输出优化模板

    0. 在有些输入数据很多的变态题中,scanf会大大拖慢程序的时间,cin就更慢了,所以就出现了读入优化.其原理就是一个一个字符的读入,输出优化同理,主要使用getchar,putchar函数. 1. ...

  3. fread读入优化,寻找速度极限

    序: 在之前的测试中,我们比较了四种读入方式,发现使用读入优化是最快的选择,但是我们知道fread()是比它更快的方法.这一次,我们对比四种读入优化,探寻C++读取速度的极限. 分别是getchar( ...

  4. OI黑科技:读入优化

    利用getchar()函数加速读入. Q:读入优化是什么? A :更加快速地读入一些较大的数字. Q:scanf不是已经够快了吗? A:Naive,scanf还是不!够!快! Q:那怎么办呢? A:我 ...

  5. ACM:读入优化

    两个简单的读入优化 int getin(){ ;; while(!isdigit(tmp=getchar()) && tmp!='-'); ,tmp=getchar(); )+(ans ...

  6. Django模板之通用模板的使用

    Django模板之通用模板的使用 转载:https://code.ziqiangxuetang.com/django/django-template.html 我们做网站有一些通用的部分,比如 导航, ...

  7. 「小程序JAVA实战」小程序通用模板的使用(17)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-17/ 小程序也为了页面增加了通用模板的功能,如何去理解一个通用的模板呢?模板的定义就是为了让我们的 ...

  8. 【ACM非算法部分】读入优化

    今天做了ACdream的比赛才知道原来还有读入优化这一说.Orz 读入一个整数的时候这么写: int a; scanf("%d",&a); 和 int a; char c; ...

  9. 读入优化&输出优化

    读入优化 int read() { ; ') ; '; ') num=num*+c-'; return ff*num; } 输出优化 void write(int x) { ) { putchar(' ...

随机推荐

  1. Mockito 2 让我们校验一些行为

    在下面的示例中,我们将会模拟(Mock)一个 List 列表. 这是因为绝大部分的人对列表这个接口比较熟悉(例如 add(), get(), clear() 方法). 在实际情况中,请不要 mock ...

  2. 一个服务器的Apache2.4.6配置多个域名

    进入到Apache的配置文件:cd /etc/httpd/conf/http.conf 在后面添加: <VirtualHost *:80> # This first-listed virt ...

  3. hive序列化和反序列化serde

    一.简介 SerDe是Serializer/Deserializer的缩写.SerDe允许Hive读取表中的数据,并将其以任何自定义格式写回HDFS. 任何人都可以为自己的数据格式编写自己的SerDe ...

  4. LeetCode 23. 合并K个排序链表(Merge k Sorted Lists)

    题目描述 合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [   1->4->5,   1->3->4,   2->6 ] 输出: ...

  5. iOS真机调试之免费预配(Free provisioning)

    免费预配允许开发者在不加入Applec Developer Program的情况下,可以发布和测试App 注意:免费预配(Free Provisioning)与自动预配(Auto Provisioni ...

  6. OSI的七层模型和TCP/IP的五层模型

    OSI七层模型: 应用层->表示层->会话层->传输层->网络层->数据链路层->物理层 TCP/IP五层模型: 应用层->传输层->网络层->数 ...

  7. 前端使用pdf.js预览pdf文件,超级简单

    现在的浏览器基本都支持直接把pdf文件拖到浏览器就可以打开了,不用安装额外的插件.但是不同的浏览器显示的页面不一样.如果我们想在网页上统一预览pdf怎样实现呢? Mozilla开源了一个插件pdf.j ...

  8. docker-compose快速部署环境笔记

    # 在含有 docker-compose.yml 的文件夹下 构建容器# 如有使用 Dockerfile 在修改 Dockerfile 文件之后再次执行如下即可应用修改docker-compose u ...

  9. 云服务器 ECS 是什么?

    云服务器 Elastic Compute Service(ECS)是阿里云提供的一种基础云计算服务.使用云服务器 ECS 就像使用水.电.煤气等资源一样便捷.高效.您无需提前采购硬件设备,而是根据业务 ...

  10. html5-meta标签和搜索引擎

    emta标签的组成: meta标签分两大部分:HTTP-EQUIV  和  NAME  变量. HTTP-EQUIV:HTTP-EQUIV类似于HTTP的头部协议,它回应给浏览器一些有用的信息,以帮助 ...