C++快读
写在前面:
一个小专题
完全非原创,不知道原来是谁提出的
诈尸
http://thepingaslord.deviantart.com/art/The-Evening-Prior-312446336
- FR0X01
1 #include<bits/stdc++.h>
2
3 using namespace std;
4
5 int a,b;
6 double c,d;
7
8 void readint(int &x){
9 x=0;int neg=1;
10 char c=getchar();
11 while(c<'0'||c>'9'){
12 if(c=='-') neg=-1;
13 c=getchar();
14 }
15 while(c>='0'&&c<='9'){
16 x=10*x+c-'0';
17 c=getchar();
18 }
19 x*=neg;
20 return;
21 }
22
23 void read(double &x){
24 x=0;double y=0.1,neg=1.0;
25 char c=getchar();
26 while(c<'0'||c>'9'){
27 if(c=='-') neg=-1.0;
28 c=getchar();
29 }
30 while(c>='0'&&c<='9'){
31 x=10*x+c-'0';
32 c=getchar();
33 }
34 if(c=='.'){
35 c=getchar();
36 while(c>='0'&&c<='9'){
37 x+=y*(c-'0');
38 y/=10;
39 c=getchar();
40 }
41 }
42 x*=neg;
43 return;
44 }
45
46 int main()
47 {
48 readint(a);readint(b);
49 read(c);read(d);
50
51 printf("%d\n%d\n",a,b);
52 printf("%lf\n%lf\n",c,d);
53
54 return 0;
55 }
- FR0X02不定长度
#include<bits/stdc++.h> using namespace std; char getint(int &x){
x=0;int neg=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') neg=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=10*x+c-'0';
c=getchar();
}
x=x*neg;
return c;
} int main()//利用快读读不定个数
{
int x,y,w;
for(int i=1;i<=3;++i)
{
char c;w=0;
getint(x);c=getint(y);
if(c!='\n') getint(w);
if(w) printf("%d %d %d\n",x,y,w);
else printf("%d %d\n",x,y);
}
return 0;
}
- AdvancedFR
1 #include<iostream>
2 #include<cstdio>
3
4 using namespace std;
5
6 inline char GC(){
7 static char buf[100010],*p1=buf,*p2=buf;
8 return (p1==p2&&(p2=(p1=buf)+fread(buf,1,100010,stdin),p1==p2))? EOF:*p1++;
9 }
10
11 void READ(int &x){
12 x=0;int neg=1;char c=GC();
13 while(c<'0'||c>'9'){if(c=='-')neg=-1;c=GC();}
14 while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c-'0');c=GC();}
15 x*=neg;
16 }
17
18 int main(int arg,char *argv[],char *enc[])
19 {
20 freopen("game.in","r",stdin);freopen("game.out","w",stdout);
21
22 fclose(stdin);fclose(stdout);
23 return 0;
24 }
(NOIP2018亲测能用)
例子:
1 #include<bits/stdc++.h>
2 #define reg register
3 using namespace std;
4
5 int U_Rarity;
6 char E_Pie[10010];
7
8 inline char GC(){
9 static char buf[100010],*p1=buf,*p2=buf;
10 return (p1==p2&&(p2=(p1=buf)+fread(buf,1,100010,stdin),p1==p2))? EOF:*p1++;
11 }
12
13 int main(int arg,char *argv[],char *enc[]){
14 freopen("winterwrapup.in","r",stdin);freopen("winterwrapup.out","w",stdout);
15
16 int E_Pie_len=0;
17 for(reg int i=1;i<=10000;++i){
18 E_Pie[i]=GC();
19 ++E_Pie_len;
20 if(E_Pie[i]==10) break;
21 }
22 for(reg int i=1;i<=E_Pie_len;++i) printf("%c",E_Pie[i]);
23 printf("\nLength:%d",E_Pie_len);
24
25 fclose(stdin);fclose(stdout);
26 return 0;
27 }
比速度的话,AdvancedFR能够吊打基础快读
C++快读的更多相关文章
- 卡常三连(快读快写+re)
快读: inline int in() { char ch; ; '))); a*=;a+=ch-'; ,a+=ch-'; return a; } 快写: inline void out(int a) ...
- C++手写快读详解(快速读入数字)
众所周知,C++里是自带读入的(这不废话吗) 例如: int a; cin>>a; 这样的读入理解简单,适合初学者,但是非常慢. 再例如: int a; scanf("%d&qu ...
- 快读&快写模板【附O2优化】
快读&快写模板 快读快写,顾名思义,就是提升输入和输出的速度.在这里简单介绍一下几种输入输出的优劣. C++ cin/cout 输入输出:优点是读入的时候不用管数据类型,也就是说不用背scan ...
- C/C++快读(快速读入)有多——安全AC
在一些算法题目中中,有的程序会被卡常(数),就是说,程序虽然渐进复杂度,(通俗来讲:算法的时间复杂度)可以接受,但因为算法本身的时间常数过大,导致程序在一些算法竞赛中超时.这是,快读就显得尤为重要了. ...
- C++读入神器——文操快读(oj也可以用)
当某天,本蒟蒻沉迷于卡常的时候: 我-- 突然,YYKdalao说:用文操快读啊! 然后 喔-目瞪口呆 不多说,上源码: 本来用的读入方式: inline void Read( int &x ...
- int快读
昨天偶然间看到CJ_tony的快读,所以便决定学习一下. 这个快读的原理就是:读入单个字符要比读入读入数字快,先读入字符,然后再转化成数字.(原理的话大学再研究) 代码: #include<io ...
- c++快读与快输模板
快读 inline int read() { ; ; char ch=getchar(); ; ch=getchar();} )+(X<<)+ch-'; ch=getchar();} if ...
- c++ 快读快输模板
快读 inline int read() { ; ; char ch=getchar(); ; ch=getchar();} )+(X<<)+ch-'; ch=getchar();} if ...
- C++快读模板
C++的快速读入模板 inline int read() { ; char ch = getchar(); ') { if (ch == '-') flag = true; ch = getchar( ...
- [C/C++]快速读入代码(快读)
快读 1.为什么要有快读 好吧,有些题目看上去十分简单,例如https://www.luogu.com.cn/problem/P4305这道题,实际上数据量巨多,光是一个测试点就可能有几个MB,在这种 ...
随机推荐
- 安装weblogic 11g
参考 https://blog.csdn.net/z69183787/article/details/38401013 https://blog.csdn.net/wjf8882300/article ...
- MybatisPlus多数据源及事务解决思路
关于多数据源解决方案 目前在SpringBoot框架基础上多数据源的解决方案大多手动创建多个DataSource,后续方案有三: 继承org.springframework.jdbc.datasour ...
- python—base64
今天在写题时,执行脚本又报错了 脚本如下 #! /usr/bin/env python3 # _*_ coding:utf-8 _*_ import base64 # 字典文件路径 dic_file_ ...
- python optparse模块的用法
引用原博主文章链接: https://www.cnblogs.com/darkpig/p/5717902.html
- 【一天一个知识点系列】- Http之状态码
状态码 简介 HTTP 状态码负责表示客户端 HTTP 请求的返回结果. 标记服务器端的处理是否正常. 通知出现的错误等工作 作用及类别 作用:状态码告知从服务器端返回的请求结果 状态码的类别 注意: ...
- SAP轻松访问会话管理器等设置
对于SAP的登陆后初始界面,是有一个配置表,可以进行设置的,例如隐藏SAP的标准菜单,设置轻松访问页面右边的图片内容等等这一切的设置都可以通过维护SSM_CUST表来实现可以通过SM30来维护内容,该 ...
- django之orm单表查询
这几天重新学习了一下django的orm,以此作为记录来分享. Part1:修改配置,生成表 在写数据和查数据之前,首先先得把django配置一下,具体配置如下: 1.先在公共项目的settings中 ...
- dict 切片 间隔取值
1. 字典型d[k].d.get(k),如果键名不存在 报错.返回None 2. 可以为键设置不存在情况的下的覆盖None的返回值 3. 字符串str可以看成是list 4. 对字符串的截取通过切片实 ...
- redis学习教程五《管道、分区》
redis学习教程五<管道.分区> 一:管道 Redis是一个TCP服务器,支持请求/响应协议. 在Redis中,请求通过以下步骤完成: 客户端向服务器发送查询,并从套接字读取,通常以阻 ...
- java架构《并发线程高级篇一》
本章主要记录讲解并发线程的线程池.java.util.concurrent工具包里面的工具类. 一:Executor框架: Executors创建线程池的方法: newFixedThreadPool( ...