输入输出模板

16级赵子潇  •  4年前


//最快的
namespace fast_IO {
    const int IN_LEN = 50000000, OUT_LEN = 50000000;
    char ibuf[IN_LEN], obuf[OUT_LEN], *ih = ibuf + IN_LEN, *oh = obuf;
    char *lastin = ibuf + IN_LEN;
    const char *lastout = ibuf + OUT_LEN - 1;
    inline char getchar_() {
        if (ih == lastin)lastin = ibuf + fread(ibuf, 1, IN_LEN, stdin), ih = ibuf;
        return (*ih++);
    }
    inline void putchar_(const char x) {
        if (ih == lastout)fwrite(obuf, 1, oh - obuf, stdout), oh = obuf;
        *oh++ = x;
    }
    inline void flush() { fwrite(obuf, 1, oh - obuf, stdout); }
}
using namespace fast_IO;
#define getchar() getchar_()
#define putchar(x) putchar_((x))
inline ll read () {
    ll ret = 0; char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret;
}
void out (ll x) { if (x >= 10) out(x / 10); putchar(x % 10 + '0'); }
//一般使用足够
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline char getc(){
	return p1==p2 && (p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
} 
inline void read(int &x){
	x = 0;char s = getc();int f = 1;
	while(!isdigit(s)){
		if(s == '-')f = -1;
		s = getc();
	}
	while(isdigit(s)){
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getc();
	}
	x *= f;
}
//请注意配合freopen使用

评论:

听说第一种在最后要加flush()


18级王浩宇  •  4年前

%%


18级张钰晨  •  4年前

%%


16级钟煜奇  •  4年前

namespace IO{

char ibuf[1<<20],*ip1=0,*ip2=0;
char gc(){if(ip1==ip2)ip1=ibuf,ip2=ibuf+fread(ibuf,1,1<<20,stdin);return ip1==ip2?EOF:*ip1++;}
char obuf[1<<20],*op1=obuf,*op2=obuf+(1<<20);
void flush(){fwrite(obuf,1,op1-obuf,stdout);}
void pc(char c){*op1++=c;if(op1==op2)flush(),op1=obuf;}
struct ioo{ioo(){}~ioo(){flush();}}ioo;

}; using namespace IO; int read(){

int ret=0,t=1;char c=gc();
while((c<'0'||c>'9')&&c!='-')c=gc();if(c=='-')t=-1,c=gc();
while(c>='0'&&c<='9')ret=ret*10+c-'0',c=gc();return ret*t;

} void print(int x){

if(x==0){pc('0');return;}if(x<0)pc('-'),x=-1;
static char buf[20],bufl;while(x)buf[++bufl]=x%10,x/=10;
while(bufl)pc('0'+buf[bufl--]);

}



张老师  •  1年前

namespace IO{

char ibuf[1<<20],*ip1=0,*ip2=0;
char gc(){if(ip1==ip2)ip1=ibuf,ip2=ibuf+fread(ibuf,1,1<<20,stdin);return ip1==ip2?EOF:*ip1++;}
char obuf[1<<20],*op1=obuf,*op2=obuf+(1<<20);
void flush(){fwrite(obuf,1,op1-obuf,stdout);}
void pc(char c){*op1++=c;if(op1==op2)flush(),op1=obuf;}
struct ioo{ioo(){}~ioo(){flush();}}ioo;

}; using namespace IO; int read(){

int ret=0,t=1;char c=gc();
while((c<'0'||c>'9')&&c!='-')c=gc();if(c=='-')t=-1,c=gc();
while(c>='0'&&c<='9')ret=ret*10+c-'0',c=gc();return ret*t;

} void print(int x){

if(x==0){pc('0');return;}if(x<0)pc('-'),x=-1;
static char buf[20],bufl;while(x)buf[++bufl]=x%10,x/=10;
while(bufl)pc('0'+buf[bufl--]);

}

fyq & jbh's LCA  •  1年前
#include<bits/stdc++.h>
#define isd(ch) ((ch)>='0'&&(ch)<='9')
using namespace std;
//io
char buf[1<<20],*S=buf,*E=buf;
inline char gc(){
	(S==E)&&(E=(S=buf)+fread(buf,1,1<<20,stdin));
	return S==E?EOF:*S++;
}
char buf2[1<<20];int topp=0;
inline void flush(){
	fwrite(buf2,1,topp,stdout);topp=0;
}
inline void pc(char c){
	buf2[topp++]=c;
	if(topp==(1<<20)) fwrite(buf2,1,topp,stdout),topp=0;
}
//#define gc getchar
//#define pc putchar
// 
inline int read(){
	int t=0,f=1;char ch=gc();
	while(!isd(ch)){
		if(ch=='-') f=-1;ch=gc();
	}while(isd(ch)) t=t*10+ch-'0',ch=gc();
	return t*f;
}char sta[15];int top=0;
inline void write(int x){
	top=0;(x<0)?pc('-'),x=-x:x=x;
	if(x==0) sta[++top]='0';
	while(x>0) sta[++top]=x%10+'0',x/=10;
	while(top>0) pc(sta[top--]);
}
int ans=0;
int main(){
    int n=read();
	for(int i=1;i<=n;++i) ans+=read();
    write(ans);flush();
    return 0;
}

LYLAKIOIAKIOI  •  3个月前