60pts重载运算符求助
查看原帖
60pts重载运算符求助
1378783
DESTRUCTION_WA楼主2024/12/25 12:58
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable:4996);
namespace Wint{
	struct wint:vector<int>{
	    wint(int n = 0){
	        push_back(n);
	        check();
	    }
	    wint& check(){
	        while(!empty() && !back()){
	            pop_back();
	        }
	        if(empty()){
	            return *this;
	        }
	        for(int i=1;i < size();++i){
	            (*this)[i] += (*this)[i-1] / 10;
	            (*this)[i-1] %= 10;
	        }
	        while(back()>=10){
	            push_back(back() / 10);
	            (*this)[size()-2] %= 10;
	        }
	        return *this;
	    }
	};
	istream& operator>>(istream& is,wint &n){
	    string s;
	    is >> s;
	    n.clear();
	    for(int i = s.size()-1;i >= 0;--i){
	        n.push_back(s[i] - '0');
	    }
	    return is;
	}
	ostream& operator<<(ostream &os,const wint &n){
	    if(n.empty()){
	        os << 0;
	    }
	    for(int i = n.size()-1;i >= 0;--i){
	        os<<n[i];
	    }
	    return os;
	}
	wint& operator-=(wint &a,wint b){
	    if(a < b){
	        swap(a,b);
	        putchar('-');
	    }
	    for(int i = 0;i != b.size();a[i] -= b[i],++i){
	        if(a[i] < b[i]){
	            int j = i + 1;
	            while(!a[j]){
	                ++j;
	            }
	            while(j>i){
	                --a[j];
	                a[--j] += 10;
	            }
	        }
	    }
	    return a.check();
	}
	wint operator-(wint a,const wint &b){
	    return a-=b;
	}
}
using namespace Wint;
int main() {
    
    wint a,b;
    cin >> a >> b;
    cout << a - b;
    
    return 0;
}

你没看错,就是*度百科上面的模板

2024/12/25 12:58
加载中...