对于基础读入读出,有基本的快读:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #define isdi(a) ((a)>='0'&&(a)<='9') #define gc getchar() #define pc(a) putchar(a) #define writeln(a) write(a,'\n')
template<typename T> void read(T&r) { r=0;char ch=gc,last='z'; while(!isdi(ch)) last=ch,ch=gc; while(isdi(ch)) r=(r<<1)+(r<<3)+(ch^48),ch=gc; if(last=='-') r=-r; }
int buf[100],len_; template<typename T> void write(T r,char endc=' ') { if(r<0) pc('-'),r=-r; len_=0; do buf[len_++]=r%10; while(r/=10); for(int i=len_-1;i>=0;i--) pc(buf[i]+'0'); pc(endc); }
|
根据这个基本快读,结合不定参数,可以得到加强版 reads
和 writes
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<bits/stdc++.h> #define isdi(a) ((a)>='0'&&(a)<='9') #define gc getchar() #define pc(a) putchar(a) #define writeln(a) write(a,'\n') using namespace std;
template<typename T> void read(T&r) { r=0;char ch=gc,last='z'; while(!isdi(ch)) last=ch,ch=gc; while(isdi(ch)) r=(r<<1)+(r<<3)+(ch^48),ch=gc; if(last=='-') r=-r; }
template<typename... T> void reads(T& ...rr) { for(auto r:{&rr...}) { (*r)=0;char ch=gc,last='z'; while(!isdi(ch)) last=ch,ch=gc; while(isdi(ch)) (*r)=((*r)<<1)+((*r)<<3)+(ch^48),ch=gc; if(last=='-') (*r)=-(*r); } }
int buf[100],len_; template<typename T> void write(T r,char endc=' ') { if(r<0) pc('-'),r=-r; len_=0; do buf[len_++]=r%10; while(r/=10); for(int i=len_-1;i>=0;i--) pc(buf[i]+'0'); pc(endc); }
template<typename... T> void writes(T ...ww) { char endc=' '; for(auto w:{ww...}) { if(w<0) pc('-'),w=-w; len_=0; do buf[len_++]=w%10; while(w/=10); for(int i=len_-1;i>=0;i--) pc(buf[i]+'0'); pc(endc); } pc('\n'); }
|
reads
支持多参数;
writes
支持多参数,且输出格式为 "%d %d ... %d \n"
注: 请注意格式,以及不要用错了。