求助,只有10分

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

Linisdjxmk @ 2024-09-24 10:17:09

#include <stdio.h>
#include <stdlib.h>

struct timeans{
    int hour;
    int minans;
};
struct timeans *minute_mi(int src, int tomin)
{
    int k = src - tomin;
    if(k >= 0)
    {
        struct timeans * ret = malloc(sizeof(struct timeans));
        ret -> hour = 0;
        ret -> minans = k;
        return ret;
    }
    else
    {
        int c = 0;
        while(k < 0)
        {
            c ++;
            k += 60;
        }
        struct timeans * ret = malloc(sizeof(struct timeans));
        ret -> hour = c;
        ret -> minans = k;
        return ret;
    }
}

int hour_mi(int src, int tomin)
{
    if(src >= tomin)
    {
        return src - tomin;
    }
    else
    {
        int t = src - tomin;
        while (t < 0)
        {
            t += 24;
        }
        return t;
    }
}

int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a % b != 0)
    {
        while(a % b != 0 && b > 0)
        {
            b--;
        }
    }
    int t1 = a / b;
    struct timeans * ans = minute_mi(50, a / b);
    printf("%02d:%02d\n",hour_mi(7,ans -> hour), ans -> minans);
    free(ans);
    return 0;
}

|