输入输出外挂模板

来源:互联网 发布:微信淘宝群怎么做到的 编辑:程序博客网 时间:2024/06/07 22:13

对于输入数据比较多的情况下,输入输出外挂可以节省不少时间。大神开挂过题博客

这是一个多个数相加,介绍一下输入输出外挂模板;

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int Scan()     //输入外挂{    int res=0,ch,flag=0;    if((ch=getchar())=='-')        flag=1;    else if(ch>='0'&&ch<='9')        res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')        res=res*10+ch-'0';    return flag?-res:res;}void Out(int a)    //输出外挂{if(a>9)        Out(a/10);    putchar(a%10+'0');}int main(){int sum=0,n;scanf("%d",&n);for(int i=0;i<n;i++){sum+=Scan();}Out(sum);return 0;}


增强版:

//输入挂 const int MAXS = 60*1024*1024;char buf[MAXS],*ch;int read(){int x;    for(++ch;*ch<=32;++ch);    for(x=0;*ch>='0';++ch) x=x*10+*ch-'0';    return x;}void std_init(){    ch=buf-1;    fread(buf,1,MAXS,stdin);}