这个鬼畜做法居然过了

P1001 A+B Problem

Innate_Joker @ 2024-10-16 13:37:51

#include <stack>
#include <cstring>
#include <iostream>
#define _8192int(x) _int8192::intTO_int8192(x)
using namespace std;
class _int8192 {
    private:
        static const int BIT = 2045;
        short num[BIT + 1];
        inline void getsize() {
            int i = BIT;
            while(i >= 0 && num[i] == 0) {
                i -- ;
            }
            if(i == -1) {
                size = 1;
            }
            else {
                size = i + 1;
            }
        }
        short cmp[BIT + 1];
        bool PrintBool() {
            memset(cmp,0,sizeof(cmp));
            if(memcmp(num,cmp,sizeof(short) * BIT) == 0) {
                return true;
            }
            return false;
        }
    public:
        int size;
        bool porn;
        inline void init() {
            for(register int i = 0; i <= BIT; i ++ ) {
                num[i] = 0;
            }
        }
        static _int8192 intTO_int8192(int n) {
            _int8192 ans;
            ans.init();
            if(n < 0) {
                ans.porn = false;
                n = -n;
            } else {
                ans.porn = true;
            }
            int p = 0;
            while(n != 0) {
                ans.num[p ++ ]=n % 10;
                n /= 10;
            }
            ans.getsize();
            return ans;
        }
        void read() {
            init();
            stack <short> st;
            size = 0;
            memset(num,0,sizeof(num));
            char a;
            int x;
            int p = 0;
            bool c = true;
            bool fr0 = true;
            a = getchar();
            while(1) {
                if(!((a >= '0' && a <= '9') || a == '-') || (c == false && a == '-')) {
                    break;
                }
                if(a == '-') {
                    size -- ;
                    porn = false;
                } else if(fr0 == false) {
                    st.push(a - '0');
                }
                else if(fr0 == true && a != '0') {
                    st.push(a - '0');
                    fr0 = false;
                } else {
                    size -- ;
                }
                if(c == true) {
                    c = false;
                }
                size ++ ;
                a = getchar();
            }
            for(register int i = 0; i < size; i ++ ) {
                num[i] = st.top();
                st.pop();
            }
            if(size == 0) {
                size = 1;
                num[0] = 0;
            }
        }
        void print() {
            if(num[0] == -8) {
                printf("Runtime Error! Zero(0) cannot be a divisor!");
                return;
            }
            if(num[0] == -9) {
                printf("Runtime Error! Zero(0) to the power of zero(0) is undefined!");
                return;
            }
            if(PrintBool() == true) {
                printf("0");
                return;
            }
            if(porn == false) printf("-");
            int p=size - 1;
            while(p != -1) {
                printf("%d",num[p]);
                p -- ;
            }
        }
        void operator ^ (_int8192 &a) {
            _int8192 t;
            t = *this;
            *this = a;
            a = t;
        }
        void operator = (const _int8192 a) {
            memcpy(num,a.num,sizeof(short) * BIT);
            porn = a.porn;
            size = a.size;
        }
        bool operator ! () {
            return *this == 0;
        }
        _int8192 abs() {
            _int8192 ret;
            ret = *this;
            ret.porn = true;
            return ret;
        }
        _int8192 opp() {
            _int8192 ret;
            ret = *this;
            ret.porn = !ret.porn;
            return ret;
        }
        bool operator > (const _int8192 a) const {
            if(porn == true && a.porn == false) {
                return true;
            }
            if(porn == false && a.porn == true) {
                return false;
            }
            bool ret = false;
            int bit = max(size,a.size);
            for(int i = bit - 1; i >= 0; i -- ) {
                if(num[i] > a.num[i]) {
                    ret = true;
                    break;
                } else if(num[i] < a.num[i]) {
                    ret = false;
                    break;
                }
            }
            if(porn == false) {
                return !ret;
            }
            return ret;
        }
        bool operator < (const _int8192 a) const {
            if(porn == true && a.porn == false) {
                return false;
            }
            if(porn == false && a.porn == true) {
                return true;
            }
            bool ret = false;
            int bit = max(size,a.size);
            for(int i = bit - 1; i >= 0; i -- ) {
                if(num[i] < a.num[i]) {
                    ret = true;
                    break;
                } else if(num[i] > a.num[i]) {
                    ret = false;
                    break;
                }
            }
            if(porn == false) {
                return !ret;
            }
            return ret;
        }
        bool operator == (const _int8192 a) const {
            if(porn != a.porn) {
                return false;
            }
            int bit = max(size,a.size);
            for(int i = bit - 1; i >= 0; i -- ) {
                if(num[i] != a.num[i]) {
                    return false;
                }
            }
            return true;
        }
        bool operator != (const _int8192 a) const {
            return ! (*this == a);
        }
        bool operator >= (const _int8192 a) const {
            return *this>a || *this==a;
        }
        bool operator <= (const _int8192 a) const {
            return *this<a || *this==a;
        }
        _int8192 operator + (const _int8192 a) const {
            _int8192 ans;
            ans.init();
            if(porn == a.porn) {
                ans.porn = porn;
                int bit = max(size,a.size);
                for(register int i = 0; i < bit; i ++ ) {
                    ans.num[i] += num[i] + a.num[i];
                    ans.num[i+1] = ans.num[i] / 10;
                    ans.num[i] %= 10;
                }
            } else {
                _int8192 b = a;
                _int8192 _this = *this;
                ans.porn = (b.abs() > _this.abs()) ? a.porn : porn;
                int bit = max(size,a.size);
            label:
                for(register int i = 0; i < bit; i ++ ) {
                    ans.num[i] += b.num[i] - _this.num[i];
                    if(ans.num[i] < 0) {
                        ans.num[i] += 10;
                        ans.num[i + 1] -- ;
                    }
                }
                if(ans.num[bit] < 0) {
                    memset(ans.num,0,sizeof(short) * BIT);
                    b ^ _this;
                    goto label;
                }
            }
            ans.getsize();
            return ans;
        }
        _int8192 operator - (const _int8192 a) const {
            _int8192 ans;
            ans.init();
            if(porn == a.porn) {
                _int8192 b = a;
                _int8192 _this = *this;
                ans.porn = (b.abs() < _this.abs()) ? porn : !porn;

                int bit = max(size,a.size);
                if(ans.porn != porn) b ^ _this;
                for(register int i = 0; i < bit; i ++ ) {
                    ans.num[i] += _this.num[i] - b.num[i];
                    if(ans.num[i] < 0) {
                        ans.num[i] += 10;
                        ans.num[i + 1] -- ;
                    }
                }
            } else {
                ans.porn = porn;
                _int8192 b = a;
                b = b.opp();
                int bit = max(size,b.size);
                for(register int i = 0; i < bit; i ++ ) {
                    ans.num[i] += num[i] + b.num[i];
                    ans.num[i+1] = ans.num[i] / 10;
                    ans.num[i] %= 10;
                }
            }
            ans.getsize();
            return ans;
        }
        void operator += (const _int8192 a) {
            *this = *this + a;
        }
        void operator -= (const _int8192 a) {
            *this = *this - a;
        }
        void operator ++ () {
            *this = *this + _8192int(1);
        }
        _int8192 operator ++ (int) {
            _int8192 *ret = this;
            ++ *this;
            return *ret;
        }
        void operator -- () {
            *this = *this - _8192int(1);
        }
        _int8192 operator -- (int) {
            _int8192 *ret = this;
            -- *this;
            return *ret;
        }
        _int8192 operator * (const _int8192 a) const {
            _int8192 ans;
            ans.init();
            ans.porn = (porn == a.porn) ? true : false;

            for(register int i = 0; i < size; i ++ ) {
                for(register int j = 0; j < a.size; j ++ ) {
                    ans.num[i + j] += num[i] * a.num[j];
                }
            }
            for(register int i = 0; i < BIT; i ++ ) {
                ans.num[i+1] += ans.num[i] / 10;
                ans.num[i] %= 10;
            }
            ans.getsize();
            return ans;
        }
        _int8192 operator / (const _int8192 a) const {
            if(a == _8192int(0)) {
                _int8192 re;
                re.init();
                re.num[0] = -8;
                return re;
            }
            _int8192 ans;
            ans.init();
            _int8192 _this = *this;
            _int8192 b = a;
            _this = _this.abs();
            b = b.abs();
            ans = _8192int(0);
            while(_this >= b) {
                _this -= b;
                ans ++ ;
            }
            ans.porn = ans.porn = (porn == a.porn) ? true : false;
            ans.getsize();
            return ans;
        }
        _int8192 operator%(const _int8192 a) const {
            if(a == 0) {
                _int8192 re;
                re.init();
                re.num[0] = -8;
                return re;
            }
            _int8192 ans;
            ans.init();
            _int8192 _this = *this;
            _int8192 b = a;
            _this = _this.abs();
            b = b.abs();
            while(_this >= b)  {
                _this -= b;
            }
            if(porn == a.porn) ans = _this;
            else ans = b - _this;
            ans.porn = a.porn;
            ans.getsize();
            return ans;
        }
        void operator *= (const _int8192 a) {
            *this = *this*a;
        }
        void operator /= (const _int8192 a) {
            *this = *this / a;
        }
        void operator %= (const _int8192 a) {
            *this =* this % a;
        }
        _int8192 operator + (const int a) const {
            return *this + _8192int(a);
        }
        _int8192 operator - (const int a) const {
            return *this - _8192int(a);
        }
        _int8192 operator * (const int a) const {
            return *this * _8192int(a);
        }
        _int8192 operator / (const int a) const {
            return *this / _8192int(a);
        }
        _int8192 operator % (const int a) const {
            return *this % _8192int(a);
        }
        bool operator < (const int a) const {
            return *this < _8192int(a);
        }
        bool operator > (const int a) const {
            return *this > _8192int(a);
        }
        bool operator == (const int a) const {
            return *this == _8192int(a);
        }
        bool operator != (const int a) const {
            return *this != _8192int(a);
        }
        bool operator >= (const int a) const {
            return *this >= _8192int(a);
        }
        bool operator <= (const int a) const {
            return *this <= _8192int(a);
        }
        void operator += (const int a) {
            *this += _8192int(a);
        }
        void operator -= (const int a) {
            *this -= _8192int(a);
        }
        void operator *= (const int a) {
            *this *= _8192int(a);
        }
        void operator /= (const int a) {
            *this /= _8192int(a);
        }
        void operator %= (const int a) {
            *this %= _8192int(a);
        }
        void operator = (int a) {
            *this = _8192int(a);
        }
        friend _int8192 operator + (int a,_int8192 b) {
            return _8192int(a) + b;
        }
        friend _int8192 operator - (int a,_int8192 b) {
            return _8192int(a) - b;
        }
        friend _int8192 operator * (int a,_int8192 b) {
            return _8192int(a) * b;
        }
        friend _int8192 operator / (int a,_int8192 b) {
            return _8192int(a) / b;
        }
        friend _int8192 operator % (int a,_int8192 b) {
            return _8192int(a) % b;
        }
        _int8192 pow(_int8192 b) {
            if(b == 0 && *this != 0) {
                return _8192int(1);
            } else if(b == 0 && *this == 0) {
                _int8192 re;
                re.init();
                re.num[0] = -9;
                return re;
            }
            bool mui = true;
        label:
            _int8192 ret = *this;
            if(b.porn == true) {
                for(_int8192 i = 2; i <= b; i ++ ) {
                    ret *= *this;
                }
            } else {
                b = b.opp();
                mui = false;
                goto label;
            }
            if(mui == false)  {
                ret = 1 / ret;
            }
            ret.getsize();
            return ret;
        }
        _int8192 pow(int b) {
            return pow(_8192int(b));
        }
        _int8192() {
            init();
            porn = true;
        }
        _int8192(int n) {
            *this = _8192int(n);
            porn = true;
        }
        friend ostream& operator << (ostream &os,const _int8192 &n) {
            ios::sync_with_stdio(false);
            if(n.num[0] == -8) {
                os << "Runtime Error! Zero(0) cannot be a divisor!";
                return os;
            }
            if(n.num[0] == -9) {
                os << "Runtime Error! Zero(0) to the power of zero(0) is undefined!";
                return os;
            }
            _int8192 b = n;
            if(b.PrintBool() == true) {
                os << "0";
                return os;
            }
            if(n.porn == false) os << "-";
            int p = n.size - 1;
            while(p != -1) {
                os << n.num[p];
                p -- ;
            }
            return os;
        }
        friend istream& operator >> (istream &is,_int8192 &n) {
            ios::sync_with_stdio(false);
            n.init();
            stack <short> st;
            n.size = 0;
            memset(n.num,0,sizeof(num));
            char a;
            int x;
            int p = 0;
            bool c = true;
            bool fr0 = true;
            a = getchar();
            while(1) {
                if(!((a >= '0' && a <= '9') || a=='-') || (c == false && a == '-'))  {
                    break;
                }
                if(a == '-') {
                    n.size -- ;
                    n.porn = false;
                } else if(fr0 == false) {
                    st.push(a - '0');
                }
                else if(fr0 == true && a != '0') {
                    st.push(a - '0');
                    fr0 = false;
                } else  {
                    n.size -- ;
                }
                if(c == true) {
                    c = false;
                }
                n.size ++ ;
                a=getchar();
            }
            for(register int i = 0; i < n.size; i ++ ) {
                n.num[i] = st.top();
                st.pop();
            }
            if(n.size == 0) {
                n.size = 1;
                n.num[0] = 0;
            }
            return is;
        }
};
int main() {
    _int8192 n,m;
    cin >> n >> m;
    cout << n + m;
    return 0;
}

by blue7628_N2O @ 2024-10-16 14:00:19

999


by imsbNR @ 2024-10-16 17:58:32

你想表达什么?不要把题解发在讨论区 jbl


by qinshanruhua @ 2024-10-18 12:35:18

看不懂啊思密达呜呜呜,你们都好牛啊


by PION_ @ 2024-10-18 14:55:35

可以解释亿下吗


by LionBlaze @ 2024-10-18 17:28:24

@PION_ 目测是高精(我寻思着我打的 OOP 高精也没这么长啊)。


by Sailor_2013 @ 2024-10-18 22:23:43

你们咋都那么厉害


by PION_ @ 2024-10-19 19:02:54

@LionBlaze OMG没学过


by HXZ2013 @ 2024-10-19 19:58:43

666


by shen_shi @ 2024-10-19 22:23:31

我里格骚刚


by xzh_2013 @ 2024-10-21 16:43:56

666666


| 下一页