80分求助

P5707 【深基2.例12】上学迟到

jw19521 @ 2024-12-14 19:30:39

求助qwq

#include <stdio.h>
int main(){
    int s,v,t,t1=0,time,h,m;
    scanf("%d %d",&s,&v);
    if(s%v==0){
        t1=s/v;
    }else if(s%v!=0){
        t1=s/v+1;
    }
    t=t1+10;
    if(t>480){
        time=1440-(t-480);
    }else{
        time=480-t;
    }
    h=time/60;
    m=time-60*h;
    if(m!=0){
        if(h>=10){
            printf("%d:%d",h,m);
        }else{
            printf("0%d:%d",h,m);
        }
    }else{
        if(h>=10){
            printf("%d:00",h);
        }else{
            printf("0%d:00",h);
        }
    }
    return 0;
}

by FastIO_DP @ 2024-12-14 19:50:17

@jw19521

if(h>=10){
    printf("%d:%d",h,m);
}else{
    printf("0%d:%d",h,m);
}

这段代码没有考虑m的位数为1的情况吧

把这段代码改成这样就AC了

if(h>=10){
    printf("%d:%02d",h,m);
}else{
    printf("0%d:%02d",h,m);
}

by jw19521 @ 2024-12-14 20:05:49

@FastIO_DP@FastIO_DP@[FastIO_DP](luogu://user/139099@FastIO_DP 谢谢啦


|