forked from tarun620/ACM-ICPC-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
here is a fast way to input integers/long longs
i realized that there are no codes to help make input faster... so here goes nothing. to make it long long just change the data types.
- Loading branch information
1 parent
0d4886c
commit 1014981
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
inline int readInt_neg() { | ||
int x = 0; | ||
bool neg=false; | ||
char ch = getchar(); | ||
while ((ch < '0' || ch > '9') && ch!='-') ch = getchar(); | ||
if (ch=='-'){ | ||
neg=true; | ||
ch=getchar(); | ||
} | ||
while (ch >= '0' && ch <= '9'){ | ||
x = (x << 3) + (x << 1) + ch - '0'; | ||
ch = getchar(); | ||
} | ||
if (neg){ | ||
return -x; | ||
} | ||
return x; | ||
} | ||
inline int readInt_non_neg() { | ||
int x = 0; | ||
bool neg=false; | ||
char ch = getchar(); | ||
while (ch < '0' || ch > '9') ch = getchar(); | ||
while (ch >= '0' && ch <= '9'){ | ||
x = (x << 3) + (x << 1) + ch - '0'; | ||
ch = getchar(); | ||
} | ||
return x; | ||
} | ||
// can replace getchar() with getchar_unlock() if its faster | ||
// this is significantly faster than scanf | ||
int main(){ | ||
printf("%d\n",readInt_non_neg()); //use this for non negative number | ||
printf("%d\n",readInt_neg()); // use this for negative number | ||
return 0; | ||
} |