#include<bits/stdc++.h>
using namespace std;
class BigInt{
private:
vector<int> num;
bool isnegative=0;
public:
size_t size(){
return num.size();
}
string get_num(){
string s;
if(isnegative)s+='-';
for(auto x:num)s+=char(x+'0');
return s;
}
BigInt(){}
~BigInt(){}
BigInt(string s){
int f=0;
if(s[0]=='-'){
f=1,isnegative=1;
}
for(;f<(int)s.size();f++)num.push_back(s[f]-'0');
}
BigInt(char* s){
int f=0;
if(s[0]=='-'){
f=1,isnegative=1;
}
for(;'0'<=s[f]&&s[f]<='9';f++)num.push_back(s[f]-'0');
}
BigInt(long long n){
if(n<0)isnegative=1,n=-n;
while(n){
num.push_back(n%10);
n/=10;
}
reverse(num.begin(),num.end());
}
void operator=(char* s){
*this=BigInt(s);
}
void operator=(long long n){
*this=BigInt(n);
}
void operator=(string s){
*this=BigInt(s);
}
BigInt operator+(BigInt other){
if (isnegative&&!other.isnegative) {
return other-*this;
}
if(!isnegative&&other.isnegative) {
return *this-other;
}
if(size()<other.size()){
BigInt ans=other;
other+=*this;
return other;
}
BigInt ans=*this;
int k=size()-other.size();
for(int i=size()-1;i>=0;i--){
int c=ans.num[i]+(i>=k?other.num[i-k]:0);
ans.num[i]=c%10;
if(c>=10){
if(i>0){
ans.num[i-1]+=c/10;
}else {
ans.num.insert(ans.num.begin(),c/10);
break;
}
}
}
return ans;
}
template<typename T>
BigInt operator+(T other){
if(other<0){
other=-other;
return *this-other;
}
BigInt temp=*this;
temp=temp+BigInt(other);
return temp;
}
BigInt& operator++(){
*this+=1;
return *this;
}
BigInt operator++(int){
BigInt temp=*this;
*this+=1;
return temp;
}
BigInt operator-(BigInt other){
BigInt result;
if(isnegative&&!other.isnegative){
result=*this;
result.isnegative=0;
result+=other;
result.isnegative=1;
return result;
}
if(!isnegative && other.isnegative){
result = *this;
result += other;
return result;
}
if(size()<other.size()||(size()==other.size()&&num<other.num)){
result = other-*this;
result.isnegative=!result.isnegative;
return result;
}
result=*this;
int k=size()-other.size();
for(int i=size()-1;i>=0;i--) {
int c=num[i]-(i>=k?other.num[i-k]:0);
if(c<0) {
c+=10;
if(i>0) {
num[i-1]--;
}else{
result.isnegative=1;
}
}
result.num[i]=c;
}
while(result.num.size()>1&&result.num[0]==0){
result.num.erase(result.num.begin());
}
return result;
}
template<typename T>
BigInt operator-(T other){
if(other<0){
return *this+other;
}
BigInt ans=*this;
ans=ans-BigInt(other);
return ans;
}
BigInt& operator--(){
*this-=1;
return *this;
}
BigInt operator--(int){
BigInt temp=*this;
*this-=1;
return temp;
}
BigInt operator*(BigInt other){
BigInt ans;
ans.num.resize(size()+other.size(),0);
ans.isnegative=(isnegative!=other.isnegative);
for(int i=size()-1;i>=0;i--) {
for(int j=other.size()-1;j>=0;j--) {
ans.num[i+j+1]+=num[i]*other.num[j];
ans.num[i+j]+=ans.num[i+j+1]/10;
ans.num[i+j+1]%=10;
}
}
while(ans.num.size()>1&&ans.num[0]==0) {
ans.num.erase(ans.num.begin());
}
return ans;
}
template<typename T>
BigInt operator*(T other){
BigInt temp=*this;
temp*=other;
return temp;
}
template<typename T>
BigInt& operator+=(T other){
*this=*this+BigInt(other);
return *this;
}
template<typename T>
BigInt& operator-=(T other){
*this=*this-BigInt(other);
return *this;
}
template<typename T>
BigInt& operator*=(T other){
*this=*this*BigInt(other);
return *this;
}
template<typename T>
bool operator<(T nums){
BigInt other=BigInt(nums);
BigInt This=*this;
if(This.isnegative&&!other.isnegative){
return 1;
}
if(!This.isnegative&&other.isnegative){
return 0;
}
if(This.isnegative&&other.isnegative){
swap(This,other);
}
if(size()!=other.size())return size()<other.size();
for(int i=size()-1;i>=0;i--){
if(other.num[i]!=This.num[i])return other.num[i]>This.num[i];
}
return 0;
}
template<typename T>
bool operator>(T nums){
return !(*this==nums||*this<nums);
}
template<typename T>
bool operator==(T nums){
BigInt other=BigInt(nums);
return isnegative==other.isnegative&&num==other.num;
}
template<typename T>
bool operator!=(T nums){
return !(*this==nums);
}
template<typename T>
bool operator<=(T nums){
return (*this==nums||*this<nums);
}
template<typename T>
bool operator>=(T nums){
return (*this==nums||*this>nums);
}
friend ostream& operator<<(ostream& os,BigInt &Bint){
os<<Bint.get_num();
return os;
}
friend istream& operator>>(istream& os,BigInt &Bint){
string s;
os>>s;
BigInt n=s;
Bint=n;
return os;
}
friend BigInt abs(BigInt _X){
_X.isnegative=0;
return _X;
}
};
int main{
//想怎么用,就怎么用
return 0;
}剪贴板
剪贴板 yftvnt09
剪贴板信息
剪贴板信息
- 收录
- 更新