-
Notifications
You must be signed in to change notification settings - Fork 2
/
__int128_input_output.cpp
41 lines (37 loc) · 1 KB
/
__int128_input_output.cpp
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
37
38
39
40
41
// __int128 input /*{{{*/
using LInt = __int128;
// logic copied from stackoverflow , I just overloaded the operators
ostream& operator<<(ostream&cout , LInt number){
auto toString = [](LInt num){
auto tenPow18 = 1000000000000000000;
std::string str;
do {
long long digits = num % tenPow18;
auto digitsStr = std::to_string(digits);
auto leading0s = (digits != num) ? std::string(18 - digitsStr.length(), '0') : "";
str = leading0s + digitsStr + str;
num = (num - digits) / tenPow18;
} while (num != 0);
return str;
};
cout << toString(number);
return cout;
}
istream& operator>>(istream&cin , LInt &number){
string s; cin >> s;
number = 0;
bool neg_flag =false;
for(auto&itr:s){
if(itr=='-'){
neg_flag = true;
continue;
}
number *= 10;
number += (itr-'0');
}
if(neg_flag){
number*=(-1);
}
return cin;
}
/*}}}*/