题目的关键点有以下几处:
- 从家到学校的时间(总分钟数)计算结果处理时要转成小数来除防止精度丢失,最后向上取整;
- 从家到学校的时间(小时部分),通过整除计算取得;从家到学校的时间(分钟部分),通过取模计算取得;
- 根据从家到学校的时间(分钟部分)是否为,决定小时部分是否需要多减。
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int s,v;
cin >> s >> v;
//读入部分
int t = ceil(static_cast<double>(s)/v);//不懂的百度去
int h = (t+10) / 60;
int m = (t+10) % 60;
//处理部分
if (m > 0)
cout << setw(2) << setfill('0') << (8 - h + 24 - 1) % 24 << ":" << setw(2) << setfill('0') << (0 - m + 60) % 60 << endl;
else
cout << setw(2) << setfill('0') << (8 - h + 24 ) % 24 << ":" << setw(2) << setfill('0') << (0 - m + 60) % 60 << endl;
//输出部分
return 0;
}