Last active
December 4, 2016 21:48
-
-
Save Sorebit/1f6ef985f2f628bd22411f70cb7dd49f to your computer and use it in GitHub Desktop.
Fast I/O for C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#define abs(a) ((a < 0) ? -(a) : (a)) | |
template <class T> | |
void print(T a) | |
{ | |
if(a == 0) | |
putchar_unlocked('0'); | |
if(a < 0) | |
putchar('-'); | |
a = abs(a); | |
char b[10]; | |
int i = 0; | |
for (; i < 10 && a; i++) | |
{ | |
b[i] = a % 10; | |
a /= 10; | |
} | |
for (i--; i >= 0; i--) | |
putchar_unlocked(b[i] + '0'); | |
} | |
template <class T> | |
void read(T & a) | |
{ | |
a = 0; | |
bool u = false; | |
char c = 0; | |
while (c < '0' || c > '9') | |
{ | |
c = getchar_unlocked(); | |
if(c == '-') | |
u = true; | |
} | |
do | |
{ | |
a *= 10; | |
a += c - '0'; | |
} while ((c = getchar_unlocked()) >= '0' && c <= '9'); | |
if(u) | |
a = -a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment