老铁们,测试点5,6是RE,这个怎么改呢

P1480 A/B Problem

Qian_Me @ 2024-10-27 12:46:40

#include <iostream>  
#include <string>  
using namespace std;  

struct hugeint {  
    long long nums[5001] = {0};  
    int len = 0;  
};  
hugeint strtoint(string s);  
hugeint div(hugeint s1, long long s2);  
void display_int(hugeint num);  

int main() {  
    string s1;  
    long long b;  
    hugeint num1, ans;  
    cin >> s1 >> b;  
    num1 = strtoint(s1);  
    ans = div(num1, b); 
    display_int(ans);  
    return 0;  
}  
hugeint strtoint(string s) {  
    hugeint ans;  
    for (int i = s.size() - 1; i >= 0; i--)  
        ans.nums[ans.len++] = s[i] - '0';  
    return ans;  
}  
hugeint div(hugeint s1, long long b) {  
    hugeint ans = {0};  
    ans.len = s1.len;  
    for (int i = s1.len - 1; i >= 0; i--) {  
        ans.nums[i] = s1.nums[i] / b;  
        s1.nums[i - 1] += s1.nums[i] % b * 10;  
    }  
    if (ans.nums[ans.len] > 0)  
        ans.len++;  
    while (ans.nums[ans.len - 1] == 0 && ans.len > 1)  
        ans.len--;  
    return ans;  
}  
void display_int(hugeint num) {  
    for (int i = num.len - 1; i >= 0; i--)  
        cout << num.nums[i];  
    cout << endl;  
}

|