TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
fast_integer_input.cpp
Go to the documentation of this file.
1
6
#include <iostream>
7
11
void
fastinput
(
int
*number) {
12
// variable to indicate sign of input integer
13
bool
negative =
false
;
14
int
c;
15
*number = 0;
16
17
// extract current character from buffer
18
c = std::getchar();
19
if
(c ==
'-'
) {
20
// number is negative
21
negative =
true
;
22
23
// extract the next character from the buffer
24
c = std::getchar();
25
}
26
27
// Keep on extracting characters if they are integers
28
// i.e ASCII Value lies from '0'(48) to '9' (57)
29
for
(; (c > 47 && c < 58); c = std::getchar())
30
*number = *number * 10 + c - 48;
31
32
// if scanned input has a negative sign, negate the
33
// value of the input number
34
if
(negative)
35
*(number) *= -1;
36
}
37
39
int
main
() {
40
int
number;
41
fastinput
(&number);
42
std::cout << number << std::endl;
43
return
0;
44
}
fastinput
void fastinput(int *number)
Definition
fast_integer_input.cpp:11
main
int main()
Definition
fast_integer_input.cpp:39
others
fast_integer_input.cpp
Generated by
1.12.0