正常版,輸入輸出優化比較正常,無論是scanf/printf/cin/cout都可以混用
用法:int x=gi; pint(x); 類似這樣。
#define gc getchar() int g_i() { int tmp=0; bool fu=0; char s; while(s=gc,s!='-'&&(s<'0'||s>'9')) ; if(s=='-') fu=1; else tmp=s-'0'; while(s=gc,s>='0'&&s<='9') tmp=tmp*10+s-'0'; if(fu) return -tmp; else return tmp; } #define gi g_i() #define pob #define pc(x) putchar(x) namespace ib {char b[100];} inline void pint(int x) { if(x==0) {pc(48); return;} if(x<0) {pc('-'); x=-x;} char *s=ib::b; while(x) *(++s)=x%10, x/=10; while(s!=ib::b) pc((*(s--))+48); }
喪病版,輸入優化采用fgets,不能與cin/scanf混用,如果需要讀入其他類型可能需要手寫。
輸出優化的行為有一些奇怪,它會把輸出緩存到一定數量之后一起輸出,可以用pob把緩存中的字符輸出,調試時可能需要注意一下(比如多個詢問的題目答案可能會在最后一起輸出)
用法也是:int x=gi; pint(x); 如果需要把緩存中的內容輸出清空就用pob;
輸入輸出緩存大小可以用BUFSIZE這個宏來控制。
#define BUFSIZE 300000 namespace fib {char b[BUFSIZE]={},*f=b;} #define gc ((*fib::f)?(*(fib::f++)):(fgets(fib::b,sizeof(fib::b),stdin)?(fib::f=fib::b,*(fib::f++)):-1)) int g_i() { int tmp=0; bool fu=0; char s; while(s=gc,s!='-'&&(s<'0'||s>'9')) ; if(s=='-') fu=1; else tmp=s-'0'; while(s=gc,s>='0'&&s<='9') tmp=tmp*10+s-'0'; if(fu) return -tmp; else return tmp; } #define gi g_i() namespace fob {char b[BUFSIZE]={},*f=b,*g=b+BUFSIZE-2;} #define pob (fwrite(fob::b,sizeof(char),fob::f-fob::b,stdout),fob::f=fob::b,0) #define pc(x) (*(fob::f++)=(x),(fob::f==fob::g)?pob:0) struct foce {~foce() {pob; fflush(stdout);}} _foce; namespace ib {char b[100];} inline void pint(int x) { if(x==0) {pc(48); return;} if(x<0) {pc('-'); x=-x;} char *s=ib::b; while(x) *(++s)=x%10, x/=10; while(s!=ib::b) pc((*(s--))+48); }
在許多oj上都交過,正確性應該沒什么問題。