50分!!神犇求助!!!!!!!

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

qaz12345678_ @ 2024-07-21 21:42:42

#include <bits/stdc++.h>
using namespace std;
int s,v;
int h = 7,m = 60;
int main()
{
    cin >> s >> v;
    m -= ((s / v + 1) % 60);
    int t = (s / v + 1) / 60;
    m -= 10;
    h -= t;
    if (m < 10)
    {
        cout << 0 << h << ":" << 0 << m;
    }
    else
    {
        cout << 0 << h << ":" << m;
    }
    return 0;
}

by littlewhite_ @ 2024-07-21 21:45:20

首先这个h=7就严重不对

题目中说了“由于路途遥远,yyy 可能不得不提前一点出发,但是提前的时间不会超过一天。”

也就是说有可能要在前一天出发

(我一开始也卡这)


by qaz12345678_ @ 2024-07-21 21:52:03

@littlewhite_ ?


by littlewhite_ @ 2024-07-21 21:55:05

@qaz12345678_ 没啥,就是说他的时间有可能花费超过8小时,就导致要在前一天出发


by qaz12345678_ @ 2024-07-21 21:59:23

@littlewhite_

#include <bits/stdc++.h>
using namespace std;
int s,v;
int h = 7,m = 60;
int main()
{
    cin >> s >> v;
    m -= ((s / v + 1) % 60);
    int t = (s / v + 1) / 60;
    m -= 10;
    h -= t;
    if (m < 10)
    {
        cout << 0 << h << ":" << 0 << m;
    }
    else
    {
        cout << 0 << h << ":" << m;
    }
    if (h < 0)
    {
        if (m < 10)
        {
            cout << 24 - h << ":" << 0 << m;
        }
        else
        {
            cout << 24 - h << ":" << m;
        }
    }
    return 0;
}

还是50分


|