Created
May 16, 2018 11:24
-
-
Save longyue0521/20c1628c0f289986be63aced625995a5 to your computer and use it in GitHub Desktop.
Reading input in C
This file contains hidden or 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
| /* https://bugdivine.blogspot.com/p/fast-input-reader-in-cc.html */ | |
| #include <stdio.h> | |
| int fastRead_int() { | |
| register int c = getchar_unlocked(); | |
| int x; | |
| x = 0; | |
| int neg = 0; | |
| for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked()); | |
| if(c=='-') { | |
| neg = 1; | |
| c = getchar_unlocked(); | |
| } | |
| for(; c>47 && c<58 ; c = getchar_unlocked()) { | |
| x = (x<<1) + (x<<3) + c - 48; | |
| } | |
| if(neg) x = -x; | |
| return x; | |
| } | |
| void fastRead_string(char *str, char delim) { | |
| register char c = 0; | |
| register int i = 0; | |
| while (c < 33) | |
| c = getchar_unlocked(); | |
| /*c != ' ' || c != '\t' || c != '\n'*/ | |
| while (c != delim) { | |
| str[i] = c; | |
| c = getchar_unlocked(); | |
| i = i + 1; | |
| } | |
| str[i] = '\0'; | |
| } | |
| int main() { | |
| int n; | |
| char s[100]; | |
| n = fastRead_int(); | |
| printf("%d\n", n); | |
| fastRead_string(s, '\n'); | |
| printf("%s\n", s); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment