为何CE

P1303 A*B Problem

Tony20120213 @ 2024-06-08 10:15:52

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>

#define PI 3.141592653

struct HIGH;

void start_random();

long long m_random(long long begin, long long end);

int int_input();

long long long_long_input();

float float_input();

double double_input();

void nums_input_int(int num[], int lenth);

void nums_input_long_long(long long num[], int lenth);

void nums_input_float(float num[], int lenth);

void nums_input_double(double num[], int lenth);

int max(int num_1, int num_2);

int min(int num_1, int num_2);

int max_of(int num[], int lenth);

int min_of(int num[], int lenth);

int max_n_of(int num[], int lenth);

int min_n_of(int num[], int lenth);

long long sum_of(int num[], int lenth);

int num_size(int num);

bool is_prime(int num);

unsigned long long fibonacci(unsigned int count);

int gcd(int num_1, int num_2);

int lcm(int num_1, int num_2);

unsigned long long factorial(int num);

bool is_num_ch(char ch);

bool is_big_letter_ch(char ch);

bool is_small_letter_ch(char ch);

void to_big(char &ch);

void to_small(char &ch);

void all_turn_to_big(std::string &str);

void all_turn_to_small(std::string &str);

void clean_line();

HIGH to_high(long long num);

//------------------------------------------------------------------------------------------------------------------------------------

struct HIGH {
    char num[5000] = {};
    int size = 1;
    bool is_neg = false;

    void input()
    {
        std::string tmp = "";

        std::cin >> tmp;
        memset(num, 0, 5000);

        size = tmp.size();
        if (tmp[0] == '-') {
            is_neg = true;
            --size;
            int size_tmp = tmp.size();
            for (int i = 0; i < size_tmp; ++i)
                tmp[i] = tmp[i + 1];
        } else {
            is_neg = false;
        }
        for (int i = 0, j = size - 1; i < size; ++i, --j)
            num[i] = tmp[j] - '0';
    }

    void print(const std::string behind)
    {
        if (is_neg)
            printf("-");
        for (int i = size - 1; i >= 0; --i) {
            printf("%d", num[i]);
        }
        std::cout << behind;
    }

    bool all_zero()
    {
        for (int i = 0; i < size; ++i) {
            if (num[i] != 0)
                return false;
        }
        is_neg = false;
        return true;
    }

    HIGH abs()
    {
        HIGH tmp;
        tmp.initial();
        tmp.size = size;
        for (int i = 0; i < size; ++i)
            tmp.num[i] = num[i];
        tmp.is_neg = false;
        return tmp;
    }

    void get_long()
    {
        while (num[size - 1] == 0 && size > 1)
            --size;
    }

    void initial()
    {
        memset(num, 0, 5000);
        size = 1;
        is_neg = false;
    }

    HIGH operator +(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];

        if (!ans.is_neg && !num_2.is_neg || ans.is_neg && num_2.is_neg) {
            ans.size = max(size, num_2.size);
            for (int i = 0; i < max(size, num_2.size); ++i) {
                ans.num[i] += num_2.num[i];
                if (ans.num[i] > 9) {
                    if (i == ans.size - 1)
                        ++ans.size;
                    ans.num[i + 1] += ans.num[i] / 10;
                    ans.num[i] %= 10;
                }
            }
        } else {
            if (ans.is_neg)
                std::swap(ans, num_2);
            char ans_big = -1;
            if (ans.size > num_2.size) {
                ans_big = 1;
            } else if (ans.size < num_2.size) {
                ans_big = 0;
            } else if (ans.size == num_2.size) {
                for (int i = ans.size - 1; i >= 0; --i) {
                    if (ans.num[i] > num_2.num[i]) {
                        ans_big = 1;
                        break;
                    } else if (ans.num[i] < num_2.num[i]) {
                        ans_big = 0;
                        break;
                    }
                }
            }
            if (ans_big == -1) {
                for (int i = 0; i < ans.size; ++i) {
                    ans.num[i] = 0;
                }
                ans.size = 1;
                ans.is_neg = false;

                return ans;
            }
            if (!ans_big)
                ans = num_2;
            for (int i = 0; i < ans.size; ++i) {
                ans.num[i] -= num_2.num[i];
                if (ans.num[i] < 0) {
                    --ans.num[i + 1];
                    ans.num[i] += 10;
                }
            }
            ans.get_long();
        }

        return ans;
    }

    void operator +=(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];

        ans = ans + num_2;
        size = ans.size;
        is_neg = ans.is_neg;
        for (int i = 0; i < ans.size; ++i)
            num[i] = ans.num[i];
    }

    HIGH operator -(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];
        bool ans_big = true;

        if (ans.size > num_2.size) {
            ans_big = true;
        } else if (ans.size < num_2.size) {
            ans_big = false;
        } else {
            for (int i = ans.size - 1; i >= 0; --i) {
                if (ans.num[i] > num_2.num[i]) {
                    ans_big = true;
                    break;
                } else if (ans.num[i] < num_2.num[i]) {
                    ans_big = false;
                    break;
                }
            }
        }

        if (!ans.is_neg && !num_2.is_neg || ans.is_neg && num_2.is_neg) {
            if (ans_big) {
                for (int i = 0; i < ans.size; ++i) {
                    ans.num[i] -= num_2.num[i];
                    if (ans.num[i] < 0) {
                        --ans.num[i + 1];
                        ans.num[i] += 10;
                    }
                }
                ans.get_long();
            } else {
                std::swap(ans, num_2);
                if (ans.is_neg)
                    ans.is_neg = false;
                else
                    ans.is_neg = true;
                for (int i = 0; i < ans.size; ++i) {
                    ans.num[i] -= num_2.num[i];
                    if (ans.num[i] < 0) {
                        --ans.num[i + 1];
                        ans.num[i] += 10;
                    }
                }
                ans.get_long();
            }
        } else {
            ans.size = max(size, num_2.size);
            for (int i = 0; i < max(size, num_2.size); ++i) {
                ans.num[i] += num_2.num[i];
                if (ans.num[i] > 9) {
                    if (i == ans.size - 1)
                        ++ans.size;
                    ans.num[i + 1] += ans.num[i] / 10;
                    ans.num[i] %= 10;
                }
            }
        }

        return ans;
    }

    void operator -=(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];

        ans = ans - num_2;
        size = ans.size;
        is_neg = ans.is_neg;
        for (int i = 0; i < ans.size; ++i)
            num[i] = ans.num[i];
    }

    HIGH operator *(HIGH num_2)
    {
        HIGH ans;
        ans.initial();

        for (int i = 0; i < num_2.size; ++i) {
            HIGH tmp;
            tmp.initial();
            tmp.is_neg = false;
            tmp.size = 0;
            for (int j = 0; j < i; ++j) {
                tmp.num[j] = 0;
                ++tmp.size;
            }
            tmp.size += size;
            for (int j = i, k = 0; k < size; ++k, ++j)
                tmp.num[j] = num[k];
            tmp.get_long();
            char tmp_2 = 0;
            for (int j = i; j < tmp.size; ++j) {
                tmp.num[j] *= num_2.num[i];
                tmp.num[j] += tmp_2;
                tmp_2 = 0;
                if (tmp.num[j] > 9) {
                    if (j == tmp.size - 1)
                        ++tmp.size;
                    tmp_2 = tmp.num[j] / 10;
                    tmp.num[j] %= 10;
                }
            }
            ans += tmp;
        }
        if (is_neg && num_2.is_neg || !is_neg && !num_2.is_neg)
            ans.is_neg = false;
        else
            ans.is_neg = true;

        return ans;
    }

    void operator *=(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];

        ans = ans * num_2;
        size = ans.size;
        is_neg = ans.is_neg;
        for (int i = 0; i < ans.size; ++i)
            num[i] = ans.num[i];
    }

    HIGH operator /(HIGH num_2)
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];
        if (temp.abs() < num_2.abs())
            return to_high(0);

        HIGH ans;
        ans.initial();
        ans.size = size - num_2.size + 1;
        for (int i = ans.size - 1; i >= 0; --i) {
            temp.initial();
            temp.size = num_2.size;
            for (int j = i + num_2.size - 1, k = num_2.size - 1; k >= 0; --j, --k)
                temp.num[k] = num[j];
            temp.get_long();
            while (temp >= num_2) {
                temp -= num_2;
                ++ans.num[i];
            }
        }
        ans.get_long();
        ans.is_neg = !(is_neg == num_2.is_neg);

        return ans;
    }

    void operator /=(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];

        ans = ans / num_2;
        size = ans.size;
        is_neg = ans.is_neg;
        for (int i = 0; i < ans.size; ++i)
            num[i] = ans.num[i];
    }

    HIGH operator %(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];

        ans -= ans / num_2 * num_2;

        return ans;
    }

    void operator %=(HIGH num_2)
    {
        HIGH ans;
        ans.size = size;
        ans.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            ans.num[i] = num[i];

        ans = ans % num_2;
        size = ans.size;
        is_neg = ans.is_neg;
        for (int i = 0; i < ans.size; ++i)
            num[i] = ans.num[i];
    }

    bool operator ==(HIGH num_2)
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];
        HIGH temp_2 = num_2 - temp;
        if (temp_2.all_zero())
            return true;
        else
            return false;
    }

    bool operator !=(HIGH num_2)
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];
        HIGH temp_2 = num_2 - temp;
        if (temp_2.all_zero())
            return false;
        else
            return true;
    }

    bool operator >(HIGH num_2)
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];
        HIGH temp_2 = temp - num_2;
        if (!temp_2.is_neg && !temp_2.all_zero())
            return true;
        else
            return false;
    }

    bool operator <(HIGH num_2)
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];
        HIGH temp_2 = num_2 - temp;
        if (!temp_2.is_neg && !temp_2.all_zero())
            return true;
        else
            return false;
    }

    bool operator >=(HIGH num_2)
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];
        HIGH temp_2 = temp - num_2;
        if (!temp_2.is_neg)
            return true;
        else
            return false;
    }

    bool operator <=(HIGH num_2)
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];
        HIGH temp_2 = num_2 - temp;
        if (!temp_2.is_neg)
            return true;
        else
            return false;
    }

    HIGH operator ++()
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];

        temp += to_high(1);
        size = temp.size;
        is_neg = temp.is_neg;
        for (int i = 0; i < temp.size; ++i)
            num[i] = temp.num[i];

        return temp;
    }

    HIGH operator --()
    {
        HIGH temp;
        temp.size = size;
        temp.is_neg = is_neg;
        for (int i = 0; i < size; ++i)
            temp.num[i] = num[i];

        temp -= to_high(1);
        size = temp.size;
        is_neg = temp.is_neg;
        for (int i = 0; i < temp.size; ++i)
            num[i] = temp.num[i];

        return temp;
    }

    bool lindomes() {
        for (int i = 0, j = size - 1; i < j; ++i, --j) {
            if (num[i] != num[j])
                return false;
        }
        return true;
    }
};

void start_random()
{
    srand(time(nullptr));
}

long long m_random(long long begin, long long end)
{
    return rand() % (end - begin + 1) + begin;
}

int int_input()
{
    int num = 0;
    scanf("%d", &num);
    return num;
}

long long long_long_input()
{
    long long num = 0;
    scanf("%lld", &num);
    return num;
}

float float_input()
{
    float num = 0.0f;
    scanf("%f", &num);
    return num;
}

double double_input()
{
    double num = 0.0;
    scanf("%lf", &num);
    return num;
}

void nums_input_int(int num[], int lenth)
{
    for (int i = 0; i < lenth; ++i)
        scanf("%d", &num[i]);
}

void nums_input_long_long(long long num[], int lenth)
{
    for (int i = 0; i < lenth; ++i)
        scanf("%lld", &num[i]);
}

void nums_input_float(float num[], int lenth)
{
    for (int i = 0; i < lenth; ++i)
        scanf("%f", &num[i]);
}

void nums_input_double(double num[], int lenth)
{
    for (int i = 0; i < lenth; ++i)
        scanf("%lf", &num[i]);
}

int max(int num_1, int num_2)
{
    return num_1 >= num_2 ? num_1: num_2;
}

int min(int num_1, int num_2)
{
    return num_1 < num_2 ? num_1: num_2;
}

int max_of(int num[], int lenth)
{
    int max = -1e9;

    for (int i = 0; i < lenth; ++i) {
        if (num[i] > max)
            max = num[i];
    }

    return max;
}

int min_of(int num[], int lenth)
{
    int min = 1e9;

    for (int i = 0; i < lenth; ++i) {
        if (num[i] < min)
            min = num[i];
    }

    return min;
}

int max_n_of(int num[], int lenth)
{
    int max = -1e9;
    int max_n = 0;

    for (int i = 0; i < lenth; ++i) {
        if (num[i] > max) {
            max = num[i];
            max_n = i;
        }
    }

    return max_n;
}

int min_n_of(int num[], int lenth)
{
    int min = 1e9;
    int min_n = 0;

    for (int i = 0; i < lenth; ++i) {
        if (num[i] < min) {
            min = num[i];
            min_n = i;
        }
    }

    return min_n;
}

long long sum_of(int num[], int lenth)
{
    long long sum = 0;

    for (int i = 0; i < lenth; ++i)
        sum += num[i];

    return sum;
}

int num_size(int num)
{
    int size = 0;

    while (num) {
        num /= 10;
        ++size;
    }
    if (size == 0)
        size = 1;

    return size;
}

bool is_prime(int num)
{
    if (num < 2)
        return false;
    for (int i = 2; i <= sqrt(num); ++i) {
        if (num % i == 0)
            return false;
    }
    return true;
}

unsigned long long fibonacci(unsigned int count)
{
    unsigned long long nums[50] = {1, 1};
    if (count <= 2)
        return 1;
    for (int i = 2; i < count; ++i) {
        nums[i] = nums[i - 2] + nums[i - 1];
    }
    return nums[count - 1];
}

int gcd(int num_1, int num_2)
{
    while (num_2) {
        int temp = num_2;
        num_2 = num_1 % num_2;
        num_1 = temp;
    }
    return num_1;
}

int lcm(int num_1, int num_2)
{
    return num_1 * num_2 / gcd(num_1, num_2);
}

unsigned long long factorial(int num)
{
    unsigned long long ans = 1;
    for (int i = 2; i <= num; ++i) {
        ans *= i;
    }
    return ans;
}

bool is_num_ch(char ch)
{
    if (ch >= '0' && ch <= '9')
        return true;
    return false;
}

bool is_big_letter_ch(char ch)
{
    if (ch >= 'A' && ch <= 'Z')
        return true;
    return false;
}

bool is_small_letter_ch(char ch)
{
    if (ch >= 'a' && ch <= 'z')
        return true;
    return false;
}

void to_big(char &ch)
{
    if (is_small_letter_ch(ch))
        ch -= 'a' - 'A';
}

void to_small(char &ch)
{
    if (is_big_letter_ch(ch))
        ch += 'a' - 'A';
}

void all_turn_to_big(std::string &str)
{
    for (int i = 0; i < str.size(); ++i) {
        if (is_small_letter_ch(str[i]))
            str[i] -= 'a' - 'A';
    }
}

void all_turn_to_small(std::string &str)
{
    for (int i = 0; i < str.size(); ++i) {
        if (is_big_letter_ch(str[i]))
            str[i] += 'a' - 'A';
    }
}

void clean_line()
{
    printf("\r\b");
}

HIGH to_high(long long num)
{
    HIGH ans;
    ans.initial();
    ans.size = num_size(num);
    if (num < 0)
        ans.is_neg = true;
    else
        ans.is_neg = false;
    for (int i = 0; i < ans.size; ++i) {
        ans.num[i] = num % 10;
        num /= 10;
    }

    return ans;
}

int main()
{
    HIGH num_1, num_2;
    HIGH ans;

    num_1.input();
    num_2.input();
    ans = num_1 * num_2;

    ans.print("");

    return 0;
}

本地可以过,洛谷CE。(上面的一大堆函数是从我自己写的头文件里粘过来的,除法是错的,其他没有问题)。


by Tony20120213 @ 2024-06-08 10:16:50

840行,不要见怪


by do_it_tomorrow @ 2024-06-08 10:20:00

@tony201201 加一个头文件 #include<cstring>


by Tony20120213 @ 2024-06-08 10:24:04

@do_it_tomorrow cstring 不是在 iostream 里面也有吗?


by Tony20120213 @ 2024-06-08 10:26:10

@do_it_tomorrow AC了 !!!可是为什么???


by do_it_tomorrow @ 2024-06-08 10:31:14

@tony201201 不是您不看洛谷给的报错信息吗?


by Tony20120213 @ 2024-06-08 10:44:02

@do_it_tomorrow 有这东西吗?


by do_it_tomorrow @ 2024-06-08 10:46:16

@tony201201 https://www.luogu.com.cn/record/161559203


|