Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define loop(i, m, n) for(int i(m);i < n;i++)
- #define pb push_back
- #define D(X) cout<<" "<<#X": "<<X<<endl;
- #define DD(A) loop(i, 0, A.size())cout << A[i] <<" ";
- #define in(x) cin >> x
- #define clr(A, V) memset(A, V, sizeof(A))
- #define ff first
- #define ss second
- #define readfile(X) freopen(X, "r", stdin)
- #define writefile(X) freopen(X, "w", stdout)
- using namespace std;
- typedef long long ll;
- typedef pair<ll,ll> pll;
- typedef vector<int> vi;
- typedef pair<int,int> pii;
- typedef vector<pii> vpii;
- typedef pair<int, string> pis;
- typedef pair<pair<int, int>, pair<int, int > > piiii;
- const int BASE = 1e9;
- vi setN(string s){
- vi n, rn;
- int c = 0;
- string t;
- for(int i = (int)s.size()-1;i>=0;i--){
- t+=s[i], c++;
- if(c == 9){
- int x;
- reverse(t.begin(), t.end());
- stringstream ss; ss << t; ss >> x;
- n.pb(x), t.clear(), c = 0;
- }
- }
- if(c){
- int x;reverse(t.begin(), t.end());
- stringstream ss; ss << t; ss >> x;
- n.pb(x);
- }
- for(int i = n.size()-1;i >=0;i--)rn.pb(n[i]);
- return rn;
- }
- string print(vi &n){
- string ans;
- loop(i, 0, (int)n.size())
- if (i == 0 && n[i]){
- stringstream ss; string x;
- ss << n[i]; ss >>x; ans+=x;
- //cout << setw(0) << n[i];
- }
- else{
- stringstream ss; string x;
- ss << n[i]; ss >>x;
- x.insert(0, 9 - (int)x.size(), '0'); ans +=x;
- //cout << setfill('0') << setw(9) << n[i];
- }
- return ans;
- }
- string add(vi &n1, vi &n2){
- vi ans;
- int i, j, sz1 = (int)n1.size(), sz2 = (int)n2.size(), carry = 0;
- if(sz1 < sz2) swap(n1, n2);
- for(i = (int)n1.size()-1, j = (int)n2.size()-1;i >= 0; i--, j--){
- j>=0? ans.pb( (carry + n1[i] + n2[j] ) % BASE), carry = (carry + n1[i] + n2[j] ) / BASE:ans.pb( (carry + n1[i]) % BASE), carry = (carry + n1[i]) / BASE;
- // if(j>=0)
- // ans.pb( (carry + n1[i] + n2[j] ) % BASE), carry = (carry + n1[i] + n2[j] ) / BASE;
- // else
- // ans.pb( (carry + n1[i]) % BASE), carry = (carry + n1[i]) / BASE;
- }
- if(carry) ans.pb(carry);
- vi anss; for(int i = (int)ans.size()-1;i>=0;i--) anss.pb(ans[i]);
- return print(anss);
- }
- string sub(vi &n1,vi &n2){
- int sz1 = (int)n1.size(), sz2 = n2.size();
- if(sz1 < sz2) swap(n1, n2);
- else if(sz1 == sz2){
- bool big = 0, f = 1;
- for(int i = 0;i < sz1 && f;i++){
- if(n2[i] > n1[i]) f = 0, big = 1;
- else if(n1[i] > n2[i]) f= 0;
- }
- if(big) swap(n1, n2);
- }
- vi ans;
- int i = (int) n1.size()-1, j = n2.size()-1, carry = 0;
- for(;i >= 0; i--, j--){
- if(j >= 0){
- if(n1[i] - n2[j]-carry >= 0)ans.pb(n1[i] - n2[j]-carry), carry = 0;
- else{
- n1[i] += BASE;
- ans.pb(n1[i] - n2[j]-carry), carry = 1;
- }
- }
- else{
- ans.pb(n1[i]-carry), carry = 0;
- }
- }
- vi anss; for(int i = (int)ans.size()-1;i>=0;i--) anss.pb(ans[i]);
- return print(anss);
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement