Skip to content

Commit 24a1a30

Browse files
committed
Fast way to read integers in I/O intensive problems
1 parent b650126 commit 24a1a30

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

readint.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// a code snippet to read integers and long long integers faster
2+
#include <bits/stdc++.h>
3+
#define ll long long
4+
using namespace std;
5+
6+
#ifndef ONLINE_JUDGE
7+
#define gc getchar
8+
#define pc putchar
9+
#else
10+
#define gc getchar_unlocked
11+
#define pc putchar_unlocked
12+
#endif
13+
14+
int read_int() {
15+
char c = gc();
16+
while((c < '0' || c > '9') && c != '-') c = gc();
17+
int ret = 0, neg = 0;
18+
if (c == '-') neg = 1, c = gc();
19+
while(c >= '0' && c <= '9') {
20+
ret = 10 * ret + c - 48;
21+
c = gc();
22+
}
23+
return neg ? -ret : ret;
24+
}
25+
26+
ll read_ll() {
27+
char c = gc();
28+
while((c < '0' || c > '9') && c != '-') c = gc();
29+
ll ret = 0;
30+
int neg = 0;
31+
if (c == '-') neg = 1, c = gc();
32+
while(c >= '0' && c <= '9') {
33+
ret = 10 * ret + c - 48;
34+
c = gc();
35+
}
36+
return neg ? -ret : ret;
37+
}
38+
39+
int main() {
40+
int n;
41+
ll k;
42+
n = read_int();
43+
k = read_ll();
44+
cout<<"n = "<<n<<" k = "<<k<<"\n";
45+
return 0;
46+
}

0 commit comments

Comments
 (0)