高精度吗.......纯模拟最高70分

lyh046 CSP-J2二等 2025-10-30 20:47:29 2025-10-30 20:51:09 4
{{ vote && vote.total.up }}

共 13 条回复

CPP 刷题王
CPP 刷题王

@wc022 wait,我在 try to write a solution to the problem。

wc022 CSP-J2二等

@CPP

问了豆包,他在int mian(){}前面加了一段这么长的代码:

istream& operator>>(istream& is, __int128& num) {
    string s;
    is >> s;  // 先读入字符串(避免直接处理__int128的IO)
    num = 0;
    bool is_negative = false;
    int i = 0;
    
    // 处理负号
    if (s[0] == '-') {
        is_negative = true;
        i = 1;
    }
    
    // 字符串转__int128
    for (; i < s.size(); ++i) {
        num = num * 10 + (s[i] - '0');
    }
    if (is_negative) num = -num;
    
    return is;
}

// 2. 重载__int128的输出运算符(cout << __int128)
ostream& operator<<(ostream& os, __int128 num) {
    // 处理0的特殊情况
    if (num == 0) {
        os << "0";
        return os;
    }
    
    // 处理负数
    if (num < 0) {
        os << "-";
        num = -num;
    }
    
    // __int128转字符串(逆序存再反转)
    string s;
    while (num > 0) {
        s.push_back(num % 10 + '0');
        num /= 10;
    }
    reverse(s.begin(), s.end());  // 反转后得到正确顺序
    
    os << s;
    return os;
}

wc022 CSP-J2二等

我去,__int128有39位数,超过了数据范围!!!

可是是像int那样直接定义吗?

CPP 刷题王

看来这题评黄没评高。

wc022 CSP-J2二等

CPP出的题还是太难了

CPP 刷题王

@wc022 你们都不知道这世界上有一个东西,叫做 __int128 吗?

lyh046 CSP-J2二等

@CPP 还是太权威了

lyh046 CSP-J2二等

是的喽QAQ

wc022 CSP-J2二等

我也不会,因为要用高精度乘法加高精度加法且还要多个数相乘相加