FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
C-Plus-Plus/others/fast_interger_input.cpp at master · SelfCodeLearning/C-Plus-Plus · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
SelfCodeLearning
/
C-Plus-Plus
Public
forked from
TheAlgorithms/C-Plus-Plus
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
C-Plus-Plus
/
others
/
fast_interger_input.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (31 loc) · 902 Bytes
Breadcrumbs
C-Plus-Plus
/
others
/
fast_interger_input.cpp
Copy path
File metadata and controls
36 lines (31 loc) · 902 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
Read integers in the fastest way in c plus plus
#
include
<
iostream
>
void
fastinput
(
int
*number) {
//
variable to indicate sign of input integer
bool
negative =
false
;
register
int
c;
*number =
0
;
//
extract current character from buffer
c =
std::getchar
();
if
(c ==
'
-
'
) {
//
number is negative
negative =
true
;
//
extract the next character from the buffer
c =
std::getchar
();
}
//
Keep on extracting characters if they are integers
//
i.e ASCII Value lies from '0'(48) to '9' (57)
for
(; (c >
47
&& c <
58
); c =
std::getchar
())
*number = *number *
10
+ c -
48
;
//
if scanned input has a negative sign, negate the
//
value of the input number
if
(negative)
*(number) *= -
1
;
}
//
Function Call
int
main
() {
int
number;
fastinput
(&number);
std::cout << number <<
"
\n
"
;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL