c++ 读入优化通用模板
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++ 读入优化通用模板的更多相关文章
- c++读入优化
对于输入数据非常大的一些可(变)爱(态)题目,scanf就会大大拖慢程序的运行速度,cin就更不用说了,所以我们要用一种高大上的东西——读入优化. 读入优化的原理其实就是一个一个字符的读入,再组成数字 ...
- c++ 读入优化、输出优化模板
0. 在有些输入数据很多的变态题中,scanf会大大拖慢程序的时间,cin就更慢了,所以就出现了读入优化.其原理就是一个一个字符的读入,输出优化同理,主要使用getchar,putchar函数. 1. ...
- fread读入优化,寻找速度极限
序: 在之前的测试中,我们比较了四种读入方式,发现使用读入优化是最快的选择,但是我们知道fread()是比它更快的方法.这一次,我们对比四种读入优化,探寻C++读取速度的极限. 分别是getchar( ...
- OI黑科技:读入优化
利用getchar()函数加速读入. Q:读入优化是什么? A :更加快速地读入一些较大的数字. Q:scanf不是已经够快了吗? A:Naive,scanf还是不!够!快! Q:那怎么办呢? A:我 ...
- ACM:读入优化
两个简单的读入优化 int getin(){ ;; while(!isdigit(tmp=getchar()) && tmp!='-'); ,tmp=getchar(); )+(ans ...
- Django模板之通用模板的使用
Django模板之通用模板的使用 转载:https://code.ziqiangxuetang.com/django/django-template.html 我们做网站有一些通用的部分,比如 导航, ...
- 「小程序JAVA实战」小程序通用模板的使用(17)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-17/ 小程序也为了页面增加了通用模板的功能,如何去理解一个通用的模板呢?模板的定义就是为了让我们的 ...
- 【ACM非算法部分】读入优化
今天做了ACdream的比赛才知道原来还有读入优化这一说.Orz 读入一个整数的时候这么写: int a; scanf("%d",&a); 和 int a; char c; ...
- 读入优化&输出优化
读入优化 int read() { ; ') ; '; ') num=num*+c-'; return ff*num; } 输出优化 void write(int x) { ) { putchar(' ...
随机推荐
- http支持上传文件夹
核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...
- Binary Stirling Numbers
http://poj.org/problem?id=1430 题目: 求 第二类 斯特林数 的 奇偶性 即 求 s2 ( n , m ) % 2 : 题解: https://blog.csdn.ne ...
- flask框架(十二):上下文管理***
情况一:单进程单线程 基于全局变量实现. 情况二:单进程多线程 基于threading.local对象. threading.local对象,用于为每个线程开辟一块空间来保存它独有的值. # -*- ...
- vue-cli3项目中引入jquery 以及如何引进bootstrap
1.安装jquery npm install jquery --save 2.或则在package.json中指定版本号,然后运行npm install命令 "dependencies&qu ...
- Anadi and Domino
C - Anadi and Domino 参考:Anadi and Domino 思路:分为两种情况: ①n<=6,这个时候肯定可以保证降所有的边都放上一张多米诺牌,那么答案就是m ②n==7, ...
- sparkOnYarn报错org.apache.hadoop.fs.FSDataInputStream
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInpu ...
- Django框架使用
---恢复内容开始--- Django 创建第一个项目 本章我们将介绍Django 管理工具及如何使用 Django 来创建项目,第一个项目我们以 HelloWorld 来命令项目. Django 管 ...
- 在Spring Boot快捷地读取文件内容的若干种方式
引言: 在Spring Boot构建的项目中,在某些情况下,需要自行去读取项目中的某些文件内容,那该如何以一种轻快简单的方式读取文件内容呢? 基于ApplicationContext读取 在Spri ...
- 在CentOS 7上搭建WordPress
环境(ECS阿里云服务器) 服务器操作系统:CentOS 7.3 : 博客部署服务器:Apache HTTP: 数据库:MySql: 框架:WordPress: 步骤 一.安装 Apache HTTP ...
- websphere gc策略调整
根据应用服务器处理的特性,适配不同的gc策略,验证程序最适合程序的gc策略: server.xml路径: xmlcells/PBOCCell/nodes/PBOCNode01/servers/PBOC ...