Skip to content

Commit 3f906fb

Browse files
committed
large num cpp
1 parent 7ed5a8b commit 3f906fb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

__int128_input_output.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
3+
typedef __int128 LInt;
4+
ostream& operator<<(ostream&cout , LInt number){
5+
auto toString = [](LInt num){
6+
auto tenPow18 = 1000000000000000000;
7+
std::string str;
8+
do {
9+
long long digits = num % tenPow18;
10+
auto digitsStr = std::to_string(digits);
11+
auto leading0s = (digits != num) ? std::string(18 - digitsStr.length(), '0') : "";
12+
str = leading0s + digitsStr + str;
13+
num = (num - digits) / tenPow18;
14+
} while (num != 0);
15+
return str;
16+
};
17+
cout << toString(number);
18+
return cout;
19+
}
20+
21+
istream& operator>>(istream&cin , LInt &number){
22+
string s; cin >> s;
23+
number = 0;
24+
bool neg_flag =false;
25+
for(auto&itr:s){
26+
if(itr=='-'){
27+
neg_flag = true;
28+
continue;
29+
}
30+
number *= 10;
31+
number += (itr-'0');
32+
}
33+
if(neg_flag){
34+
number*=(-1);
35+
}
36+
return cin;
37+
}
38+
39+

0 commit comments

Comments
 (0)