0%

快速读写挂

有时候读入数据量很大会超时,据说…这时候读写挂能派上用场
快速读写挂

1
2
3
4
5
6
7
8
9
10
11
12
int get() {
char c;
while (c = getchar(), (c < '0' || c > '9') && (c != '-'));
bool flag = (c == '-');
if (flag) c = getchar();
int x = 0;
while (c >= '0' && c <= '9') {
x = x*10 + c -48;
c = getchar();
}
return flag ? -x : x;
}

cin取消同步 ios::sync_with_stdio(false);

fread读入输出挂

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;


const int MAXBUF = 10000;
char buf[MAXBUF], *ps = buf, *pe = buf+1;

bool isdigit(char n) {
if (n >= '0' && n <= '9') return true;
return false;
}

inline void rnext()
{
if(++ps == pe)
pe = (ps = buf)+fread(buf,sizeof(char),sizeof(buf)/sizeof(char),stdin);
}

template <class T>
inline bool in(T &ans)
{
ans = 0;
T f = 1;
if(ps == pe) return false;//EOF
do{
rnext();
if('-' == *ps) f = -1;
}while(!isdigit(*ps) && ps != pe);
if(ps == pe) return false;//EOF
do
{
ans = (ans<<1)+(ans<<3)+*ps-48;
rnext();
}while(isdigit(*ps) && ps != pe);
ans *= f;
return true;
}

const int MAXOUT=10000;
char bufout[MAXOUT], outtmp[50],*pout = bufout, *pend = bufout+MAXOUT;
inline void write()
{
fwrite(bufout,sizeof(char),pout-bufout,stdout);
pout = bufout;
}
inline void out_char(char c){ *(pout++) = c;if(pout == pend) write();}
inline void out_str(char *s)
{
while(*s)
{
*(pout++) = *(s++);
if(pout == pend) write();
}
}
template <class T>
inline void out_int(T x) {
if(!x)
{
out_char('0');
return;
}
if(x < 0) x = -x,out_char('-');
int len = 0;
while(x)
{
outtmp[len++] = x%10+48;
x /= 10;
}
outtmp[len] = 0;
for(int i = 0, j = len-1; i < j; i++,j--) swap(outtmp[i],outtmp[j]);
out_str(outtmp);
}

int main()
{
freopen("in.txt", "r", stdin);
int t, ca=1;
in(t);
while(t--)
{
int n;
in(n);

out_str("Case #");
out_int(ca++);
out_str(": ");
out_int(n), out_char('n');
}
write();
return 0;
}