90分求助哇

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

dkp339 @ 2023-09-22 23:59:41

我是刚学c语言的大一新生,不过一直卡在90分不过,大佬能不能帮忙看一下是哪里出了问题吗? 以下是源代码

#include <stdio.h>
#include <math.h>

int main()
{
    int s,v,at,H,T;
    double t;
    scanf("%d %d",&s,&v);
    t = s/v;
    at = (t+1) + 10;
    if (at<=480)
    {
        H=(480-at)/60;
        T=(480-at)%60;
        printf("%.2d:%.2d\n",H,T);
    }
    else if (at>480)
    {
        H=(1920-at)/60;
        T=(1920-at)%60;
        printf("%.2d:%.2d\n",H,T);
    }
    return 0;
}

by hope88888888 @ 2023-09-23 18:15:53

t = s/v;

at = (t+1) + 10;

input
50 1
output
6:59


by dkp339 @ 2023-09-23 18:33:58

@hope88888888

在我电脑运行效果是06:59?


by dkp339 @ 2023-09-23 18:42:49

@hope88888888 是第9个测试点出错,难道是%.2d有问题吗?我看csdn上用c写这道题的是直接在printf函数里加上0的


by hope88888888 @ 2023-09-23 19:20:46

@dkp339 我少打了个0,抱歉

output

06:59

然后你没发现这个结果是错误的吗


by dkp339 @ 2023-09-23 20:37:45

@hope88888888

是我眼瞎了,谢谢大佬


by dkp339 @ 2023-09-23 20:41:22

@hope88888888

#include <stdio.h>

int main()
{
    int s,v,at,H,T,t;
    scanf("%d %d",&s,&v);
    t = s/v;
    if (s%v ==0)
        at = t +10;
    else 
        at = (t+1) + 10;
    if (at<480)
    {
        H=(480-at)/60;
        T=(480-at)%60;
        printf("%.2d:%.2d\n",H,T);
    }
    else if (at == 480)
    {
        printf("00:00\n");
    }
    else if (at>480)
    {
        H=(1920-at)/60;
        T=(1920-at)%60;
        printf("%.2d:%.2d\n",H,T);
    }
    return 0;
}

现在就好了


by hope88888888 @ 2023-09-23 20:55:08

@dkp339 祝贺

按照你的思路可以这样改

t = s/v;

-->

t = (s - 1)/v;


by dkp339 @ 2023-09-23 21:19:47

@hope88888888 谢谢大佬


|