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的options方法作用
1.HTTP的options方法作用 检测服务器所支持的请求方法.(比如:‘/user'路由支持哪些方法:get.post.delete...) CORS中的预检请求(检测某个接口是否支持跨域) 2. ...
- 上传base64图片至七牛云,并返回图片link
https://developer.qiniu.com/kodo/kb/1326/how-to-upload-photos-to-seven-niuyun-base64-code
- Mockito 2 让我们校验一些行为
在下面的示例中,我们将会模拟(Mock)一个 List 列表. 这是因为绝大部分的人对列表这个接口比较熟悉(例如 add(), get(), clear() 方法). 在实际情况中,请不要 mock ...
- eclipse打开项目中文件时左侧project explorer同时展开该文件的路径
如图,点击Package Explorer面板上的双向箭头图标即可
- 学习日记6、easyui datagrid 新增一行,编辑行,结束编辑和删除行操作记录
1.新增一行并进入编辑状态 var index=$('#Numbers').datagrid('appendRow', { CardInformation: '开户行', CardNumber: '银 ...
- 记一次关于springboot的netty版本冲突问题
冲突的地放其实很多,大概都是类似,找不到哪个方法了: 类似于: Error starting ApplicationContext. To display the conditions report ...
- $\LaTeX$数学公式大全6
$6\ Binary\ Operation/Relation\ Symbols$$\ast$ \ast$\star$ \star$\cdot$ \cdot$\circ$ \circ$\bullet$ ...
- [BZOJ4033]:[HAOI2015]树上染色(树上DP)
题目传送门 题目描述 有一棵点数为N的树,树边有边权.给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并将其他的N-K个点染成白色.将所有点染色后,你会获得黑点两两之间的距离加 ...
- vue 使用axios 出现跨域请求的两种解决方法
最近在使用vue axios发送请求,结果出现跨域问题,网上查了好多,发现有好几种结局方案. 1:服务器端设置跨域 header(“Access-Control-Allow-Origin:*”); h ...
- mongodb aggregate 聚合 操作(扁平化flatten)
mongodb自带的函数非常多,最近用mongo做持久化数据库,遇到一个需求:子文档是个数组,把数组里的各个字段扁平化合到根文档中,查过资料后(主要是mongodb的文档和stackoverflow) ...