老是80分,卡第一个和最后一个测试用例

P1480 A/B Problem

lanfy @ 2024-08-20 17:55:45

错误提示:Wrong Answer.wrong answer Too short on line 1.


by hyl_____ @ 2024-08-20 17:58:42

这是没有输出的意思


by hyl_____ @ 2024-08-20 17:59:35

@lanfy 把代码贴出来


by lanfy @ 2024-08-20 18:09:01

@hyl_____ 现在变成96了,只差第一个用例没过了。


by lanfy @ 2024-08-20 18:11:41

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

//洛谷1480:高精度/低精度
int main(){
    char dividend[5050]={};  //接收被除数的字符
    int dividend_num[5050],quotient[5050]; //被除数,商
    long long divider;  //除数
    cin>>dividend>>divider;
    if(divider==0){
        cout<<0<<endl;
        return 0;
    }
    //将字符数组的被除数转化为整型数组
    for(int i=0;i<strlen(dividend);i++){
        dividend_num[i+1] = dividend[i]-'0';
    }
    long long remainder=0;   //余数(也要long long)
    for(int j=1;j<=strlen(dividend);j++){
        quotient[j] = (dividend_num[j]+remainder*10)/divider; //商当前位置的值,新被除数=余数*10+下一位数
        remainder = (dividend_num[j]+remainder*10)%divider;   //求新余数
    }
    //去除前导0
    int index=1;
    for(int i=index;i<=strlen(dividend);i++){
        if(quotient[i]==0 && quotient[i+1]==0){
            index++;
        }
        else if(quotient[i]==0 && quotient[i+1]!=0){
            index++;
            break;
        }
        else
            break;
    }
    for(int k=index;k<=strlen(dividend);k++){
        cout<<quotient[k];
    }
    cout<<endl;
    return 0;
}

by lanfy @ 2024-08-20 18:12:55

@hyl_____ 代码在下面了老哥


by hyl_____ @ 2024-08-20 18:17:48

特判除数是0的情况


by hyl_____ @ 2024-08-20 18:18:59

我试了一下。当你除数是0的情况下不会输出


by hyl_____ @ 2024-08-20 18:19:22

@lanfy


by hyl_____ @ 2024-08-20 18:21:12

求关,以后有问题可以私信我,我一般在上午到下午五点和七点到八点在线,@lanfy


by lanfy @ 2024-08-20 23:37:30

@hyl_____ ``` //错在了去除前导0这,右侧不能取等,因为当被除数小于除数时,商为0,所以要保留一个0输出 for(int i=index;i<strlen(dividend);i++)


|