我的写法怎么有一个是Wa呀

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

yangcq @ 2024-11-06 14:39:49

#include <cstdio>

using namespace std;

int main() {
    int dis, v;
    scanf("%d%d", &dis, &v);

    int time = (dis / v) + 1 + 10;

    int end = 480;
    int beg = end - time;

    if (beg < 0) beg += 24 * 60;

    printf("%02d:%02d\n", beg / 60, beg % 60);

    return 0;
}

by NingMeng_yang @ 2024-11-06 15:19:38

int time = (dis / v) + 1 + 10; 这一行的精度没处理好, 如果 dis/v 刚好是整数, 那后边就不用加一, 所以在后边加上if (dis % v == 0) time --;


by yangcq @ 2024-11-06 18:59:01

@NingMeng_yang orz,对对对噢,谢谢0v0


|