Skip to content

Commit

Permalink
here is a fast way to input integers/long longs
Browse files Browse the repository at this point in the history
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
ash12345678987654321 authored Oct 15, 2018
1 parent 0d4886c commit 1014981
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Input/fast-input.cpp
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;
}

0 comments on commit 1014981

Please sign in to comment.