Ptilopsis_w 快读的简化版()
# V 1.0
(update: 2022.11.14)
支持整数读入输出,单字符和字符串读入输出 (Not include string),支持多参读入输出,如果读字符串只能一次传一个参。
# Example
int a; | |
char s; | |
long long b; | |
read(a, s, b); | |
print(a, s, b, ' ', "Yes\n"); | |
char S[100], T[100]; | |
read(S), read(T), print(S), print(T); |
# 完整版 Code
namespace Aniciry | |
{ | |
const int SIZE = 100000; | |
char ibuf[SIZE], obuf[SIZE], *p1, *p2, *p3 = obuf, ch; | |
#define isseen(ch) (ch > 32) | |
#define isspace(ch) (ch <= 32 and ch != EOF) | |
#define isdigit(ch) (ch >= '0' and ch <= '9') | |
#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,SIZE,stdin),p1==p2)?(EOF):(*p1++)) | |
#define putchar(ch) ((p3==(obuf+SIZE))and(fwrite(obuf,SIZE,1,stdout),p3=obuf),*p3++=(ch)) | |
struct Aniciry{ | |
~Aniciry(){ fwrite(obuf,p3-obuf,1,stdout); } | |
}dqr; | |
template <typename T> | |
inline auto read(T &x) -> void | |
{ | |
x = 0; ch = getchar(); | |
while(!isdigit(ch) and ch != EOF) ch = getchar(); | |
if(ch == EOF) return void(); | |
while(isdigit(ch)) x = x*10+(ch-'0'), ch = getchar(); | |
} | |
inline auto read(char &x) -> void | |
{ | |
x = getchar(); | |
while(isspace(x)) x = getchar(); | |
} | |
inline auto read(char *s) -> void | |
{ | |
ch = getchar(); | |
while(isspace(ch)) ch = getchar(); | |
while(isseen(ch)) *s = ch, ++s, ch = getchar(); | |
*s = '\000'; | |
} | |
inline auto print(T x) -> void{ | |
static char st[129]; int top = 0; | |
if(x < 0) putchar('-'), x = -x; | |
do{st[top++]=x%10+'0',x/=10;}while(x); | |
while(top) putchar(st[--top]); | |
} | |
inline auto print(char ch) -> void{ | |
putchar(ch); | |
} | |
inline auto print(char *s) -> void{ | |
for(int i = 0; s[i]; i += 1) putchar(s[i]); | |
} | |
inline auto print(const char *s) -> void{ | |
for(int i = 0; s[i]; i += 1) putchar(s[i]); | |
} | |
template <typename T, typename ...T1> | |
inline auto read(T &a, T1 &...other) -> void{ | |
return read(a), read(other...); | |
} | |
template <typename T, typename ...T1> | |
inline auto print(T x, T1 ...other) -> void{ | |
return print(x), print(other...); | |
} | |
} | |
using namespace Aniciry; |
# V 1.5
(update: 2022.11.20)
补充了负数的读入输出,增添了返回参式的读入 (当然也可以直接用在函数传参里了)。
# Example
int a; | |
char ch; | |
pair<int, long long> p; | |
a = read<int>(); | |
ch = read<char>(); | |
p = read<int, long long>(); | |
print(-1); | |
inline auto work(int x) -> void; | |
work(read<int>()); |
# 完整版 Code
namespace Aniciry | |
{ | |
// Never Stop Wandering, Rain Or Shine! | |
const int SIZE = 100000; | |
char ibuf[SIZE], obuf[SIZE], *p1, *p2, *p3 = obuf, ch; | |
#define isseen(ch) (ch > 32) | |
#define isspace(ch) (ch <= 32 and ch != EOF) | |
#define isdigit(ch) (ch >= '0' and ch <= '9') | |
#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,SIZE,stdin),p1==p2)?(EOF):(*p1++)) | |
#define putchar(ch) ((p3==(obuf+SIZE))and(fwrite(obuf,SIZE,1,stdout),p3=obuf),*p3++=(ch)) | |
struct ANICIRY{ int CYR; ~ANICIRY(){ fwrite(obuf,p3-obuf,1,stdout); } }DQR; | |
template <typename T> | |
inline auto read(T &x) -> void | |
{ | |
x = 0; ch = getchar(); bool flag = false; | |
while(!isdigit(ch) and ch != EOF and ch != '-') ch = getchar(); | |
if(ch == EOF) return void(); if(ch == '-') flag = true, ch = getchar(); | |
while(isdigit(ch)) x = x*10+(ch-'0'), ch = getchar(); if(flag) x = -x; | |
} | |
inline auto read(char &x) -> void | |
{ | |
x = getchar(); | |
while(isspace(x)) x = getchar(); | |
} | |
inline auto read(char *s) -> void | |
{ | |
ch = getchar(); | |
while(isspace(ch)) ch = getchar(); | |
while(isseen(ch)) *s = ch, ++s, ch = getchar(); | |
*s = '\000'; | |
} | |
template <typename T> | |
inline auto read() -> T{ | |
T x = 0; ch = getchar(); bool flag = false; | |
while(!isdigit(ch) and ch != EOF and ch != '-') ch = getchar(); | |
if(ch == EOF) return 0; if(ch == '-') flag = true, ch = getchar(); | |
while(isdigit(ch)) x = x*10+(ch-'0'), ch = getchar(); if(flag) x = -x; | |
return x; | |
} | |
template <char> | |
inline auto read() -> char | |
{ | |
ch = getchar(); | |
while(isspace(ch)) ch = getchar(); | |
return ch; | |
} | |
#ifdef _STL_PAIR_H | |
template <typename T1, typename T2> | |
inline auto read() -> pair<T1, T2> | |
{ | |
pair<T1, T2> p; | |
p.first = read<T1>(); | |
p.second = read<T2>(); | |
return p; | |
} | |
#endif | |
template <typename T> | |
inline auto print(T x) -> void{ | |
static char st[129]; int top = 0; | |
if(x < 0) putchar('-'), x = -x; | |
do{st[top++]=x%10+'0',x/=10;}while(x); | |
while(top) putchar(st[--top]); | |
} | |
inline auto print(char ch) -> void{ | |
putchar(ch); | |
} | |
inline auto print(char *s) -> void{ | |
for(int i = 0; s[i]; i += 1) putchar(s[i]); | |
} | |
inline auto print(const char *s) -> void{ | |
for(int i = 0; s[i]; i += 1) putchar(s[i]); | |
} | |
template <typename T, typename ...T1> | |
inline auto read(T &a, T1 &...other) -> void{ | |
return read(a), read(other...); | |
} | |
template <typename T, typename ...T1> | |
inline auto print(T x, T1 ...other) -> void{ | |
return print(x), print(other...); | |
} | |
} | |
using namespace Aniciry; |