【闲话】一年之后,我的码风发生了什么变化?

· · 闲话

一年前:record

#pragma GCC optmize(2) 
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct Int{
    int a[10000];
    void clear(){
        memset(a,0,sizeof(a));
    }
    Int(){
        clear();
    }
    void upd(){
        while(a[0] > 1 && !a[a[0]])a[0]--;
    }
    Int operator = (string s){
        a[0] = s.size();
        for(int i = 1;i <= a[0];i++)a[i] = s[a[0] - i] - '0';
        upd();
        return *this;
    }
    Int operator = (int num){
        string s = to_string(num);
        *this = s;
        return *this;
    }
};
istream& operator >>(istream& is,Int &a){
    string s;
    is >> s;
    a = s;
    return is;
}
ostream& operator <<(ostream& os,const Int &a){
    for(int i = a.a[0];i >= 1;i--)os << a.a[i];
    return os;
}
bool operator <(Int a,Int b){
    if(a.a[0] != b.a[0])return a.a[0] < b.a[0];
    for(int i = a.a[0];i >= 1;i--){
        if(a.a[i] != b.a[i])return a.a[i] < b.a[i];
    }
    return false;
}
bool operator >(Int a,Int b){
    return b < a;
}
bool operator <=(Int a,Int b){
    return !(a > b);
}
bool operator >=(Int a,Int b){
    return !(a < b);
}
bool operator !=(Int a,Int b){
    return a < b || b < a;
}
bool operator ==(Int a,Int b){
    return a <= b && a >= b;
}
Int operator +(Int a,Int b){
    Int c;
    c.clear();
    c.a[0] = max(a.a[0],b.a[0]) + 1;
    for(int i = 1;i <= c.a[0];i++){
        c.a[i] += (a.a[i] + b.a[i]);
        c.a[i + 1] += c.a[i] / 10;
        c.a[i] %= 10;
    }
    c.upd();
    return c;
}
Int operator -(Int a,Int b){
    Int c;
    c.clear();
    c.a[0] = min(a.a[0],b.a[0]) + 1;
    for(int i = 1;i <= c.a[0];i++){
        c.a[i] += (a.a[i] - b.a[i]);
        c.a[i + 1] -= (c.a[i] < 0);
        c.a[i] = (c.a[i] + 10) % 10;
    }
    c.upd();
    return c;
}
Int operator *(Int a,Int b){
    Int c;
    c.clear();
    c.a[0] = a.a[0] + b.a[0];
    for(int i = 1;i <= a.a[0];i++){
        for(int j = 1;j <= b.a[0];j++){
            c.a[i + j - 1] += a.a[i] * b.a[j];
        }
    }
    for(int i = 1;i < c.a[0];i++){
        c.a[i + 1] += c.a[i] / 10;
        c.a[i] %= 10;
    }
    c.upd();
    return c;
}
Int operator /(Int a,Int b){
    if(a.a[0] == 1 && a.a[1] == 0 || a < b){
        Int c;
        c = 0;
        return c;
    }
    Int tmp,c;
    c.clear();
    c.a[0] = a.a[0] - b.a[0] + 1;
    for(int i = c.a[0];i > 0;i--){
        tmp.clear();
        for(int j = 1;j <= b.a[0];j++){
            tmp.a[i + j - 1] = b.a[j];
        }
        tmp.a[0] = b.a[0] + i - 1;
        while(a >= tmp){
            a = a - tmp;
            c.a[i]++;
        }
    }
    c.upd();
    return c;
}
Int operator %(Int a,Int b){
    return (a - ((a / b) * b));
}
Int qpow(Int a,Int b){
    Int ans,num,t,t1;
    ans = 1,num = a,t = 0,t1 = 2;
    while(b > t){
        if(b % t1 != t)ans = ans * num;
        num = num * num,b = b / t1;
    }
    return ans;
}
Int jc(Int a){
    Int ans,tmp,i;ans = 1,tmp = 1;
    for(i = 1;i <= a;i = i + tmp){
        ans = ans * i;
    }
    return ans;
}
int qpow(int a,int b){
    int ans = 1,num = a;
    while(b){
        if(b & 1)ans = ans * num % 1000;
        num = num * num % 1000,b >>= 1;
    }
    return ans;
}
Int get_ans(Int a,Int b){
    return jc(a) / (jc(b) * jc(a - b));
}
signed main() {
    Int a,b,tmp1,tmp2,tmp3;
    tmp3 = 1;
    cin >> a >> b;
    cout << a + b << endl;
    if(a < b)cout << "-" << b - a << endl;
    else cout << a - b << endl;
    cout << a * b << endl;
    cout << a / b << endl;
    cout << a % b;
//  tmp1 = a - tmp3,tmp2 = qpow(b,b);
//  if(a < tmp2)return cout << 0,0;
//  tmp2 = tmp2 - tmp3;
//  cout << get_ans(tmp2,tmp1);
}

一年后:record

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e4 + 5;
struct Int{
    int a[N << 1];
    void clear(){memset(a,0,sizeof(a));}
    Int(){clear();}
    void upd(){while(a[0] > 1 && !a[a[0]])a[0]--;}
    Int operator = (string s){
        a[0] = s.size();
        for(int i = 1;i <= a[0];i++)a[i] = s[a[0] - i] - '0';
        upd();
        return *this;
    }
    Int operator =(int num){
        string s = to_string(num);
        *this = s;
        return *this;
    }
};
istream& operator >>(istream& is,Int &a){
    string s;
    is >> s;
    a = s;
    return is;
}
ostream& operator <<(ostream& os,const Int &a){
    for(int i = a.a[0];i >= 1;i--)os << a.a[i];
    return os;
}
bool operator <(Int a,Int b){
    if(a.a[0] != b.a[0])return a.a[0] < b.a[0];
    for(int i = a.a[0];i >= 1;i--){
        if(a.a[i] != b.a[i])return a.a[i] < b.a[i];
    }
    return false;
}
bool operator >(Int a,Int b){return b < a;}
bool operator <=(Int a,Int b){return !(a > b);}
bool operator >=(Int a,Int b){return !(a < b);}
bool operator !=(Int a,Int b){return a < b || b < a;}
bool operator ==(Int a,Int b){return a <= b && a >= b;}
Int operator +(Int a,Int b){
    Int c;
    c.a[0] = max(a.a[0],b.a[0]) + 1;
    for(int i = 1;i <= c.a[0];i++){
        c.a[i] += (a.a[i] + b.a[i]);
        c.a[i + 1] += c.a[i] / 10;
        c.a[i] %= 10;
    }
    c.upd();
    return c;
}
Int operator -(Int a,Int b){
    Int c;
    c.a[0] = max(a.a[0],b.a[0]);
    for(int i = 1;i <= c.a[0];i++){
        c.a[i] += (a.a[i] - b.a[i]);
        c.a[i + 1] -= (c.a[i] < 0);
        c.a[i] = (c.a[i] + 10) % 10;
    }
    c.upd();
    return c;
}
Int operator *(Int a,Int b){
    Int c;
    c.a[0] = a.a[0] + b.a[0];
    for(int i = 1;i <= a.a[0];i++){
        for(int j = 1;j <= b.a[0];j++)c.a[i + j - 1] += a.a[i] * b.a[j];
    }
    for(int i = 1;i < c.a[0];i++){
        c.a[i + 1] += c.a[i] / 10;
        c.a[i] %= 10;
    }
    c.upd();
    return c;
}
Int operator /(Int a,Int b){
    if(a.a[0] == 1 && a.a[1] == 0 || a < b){Int c;c = 0;return c;}
    Int tmp,c;
    c.a[0] = a.a[0] - b.a[0] + 1;
    for(int i = c.a[0];i > 0;i--){
        tmp.clear();
        for(int j = 1;j <= b.a[0];j++)tmp.a[i + j - 1] = b.a[j];
        tmp.a[0] = b.a[0] + i - 1;
        while(a >= tmp)a = a - tmp,c.a[i]++;
    }
    c.upd();
    return c;
}
Int operator %(Int a,Int b){return (a - ((a / b) * b));}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    Int a,b,tmp1,tmp2,tmp3;
    cin >> a >> b;
    cout << a + b << endl;
    if(a < b)cout << "-" << b - a << endl;
    else cout << a - b << endl;
    cout << a * b << endl;
    cout << a / b << endl;
    cout << a % b;
}

改变在于:

  1. 现在的码风更加紧凑,可以减少码量。
  2. 添加了更多用于减少常数的代码,避免被毒瘤题目卡常。