80分 求大犇解答

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

ORFOR @ 2024-11-26 16:26:11

#include<stdio.h>
int main()
{
    int s,v,t,h,min,a1,a2,b,b1,b2,m;
    scanf("%d %d",&s,&v);
    t=s/v;
    if(s-t*v>0) t=t+1;
    h=(t+10)/60;
    min=t+10-60*h;
    if (h<=7&&min!=0)
    {
        a1=0;   
        a2=7-h;
        b=60-min;
        printf("%d%d:%d",a1,a2,b);
    }

    if (h<=7&&min==0)
    {
        a1=0;
        a2=8-h;
        b1=0;
        b2=0;
        printf("%d%d:%d%d",a1,a2,b1,b2);
    }
    if(h>7&&min!=0)
    {
       m=31-h;
       a1=m/10;     
       a2=m-10*a1;
       b=60-min;
       printf("%d%d:%d",a1,a2,b);
    }
    if(h>7&&min==0)
    {
        m=31-h;
        a1=h/10;    
        a2=m-10*a1;
        b1=0;
        b2=0;
        printf("%d%d:%d%d",a1,a2,b1,b2);
    }

return 0;

}

by PengRuiXuan @ 2024-11-26 16:29:59

#include <stdio.h>
#include <math.h>
int main() { 
    int s, v, t;
    scanf("%d%d", &s, &v);
    t = ceil(1.0 * s / v) + 10; 
    int h = t / 60, m = t % 60; 
    int M = 60 - m, H = 7 - h;
    while (H < 0) {
        H += 24;
    }   
    printf("%02d:%02d", H, M);
    return 0; 
}

|