这个鬼畜做法居然过了

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 kkksc_tbh @ 2024-10-22 10:08:37

OTZ,%%%


by foxboo @ 2024-10-22 17:01:58

好牛逼


by Dean20130202 @ 2024-10-22 21:09:08

目测是高精,但好像加了其他多余的函数与运算符@Innate_Joker


by yuanxiaoben0407 @ 2024-10-24 17:49:46

我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚我里格骚刚


by yuanxiaoben0407 @ 2024-10-24 17:50:05

666


by shx2011 @ 2024-10-25 23:36:34

长度惊人%%%%%%%%%


by FanxtEZ @ 2024-11-02 20:14:28

太6了


by YYCk @ 2024-11-22 17:26:07

看看我的


使用 命名空间  std;
定义整型 main()
开始于
    定义整型 甲;
    定义整型 乙;
    输入 甲;
    输入 乙;
    定义长整型 答案;
    答案 等于 甲 加 乙;
    输出 答案;
    返回值 零;
结束

by ZYczc @ 2024-11-24 18:58:36

看了主函数的我:?


by wyyybb @ 2024-12-04 17:18:57

是8192位oop整数(主要功能太全了,你们只写几个)


上一页 | 下一页