跳到正文

题解

P5707题解

cola0827约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年9月10日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 1 分钟
获赞
1
题目
P5707

版本

  1. v1当前

题目的关键点有以下几处:

  1. 从家到学校的时间(总分钟数)计算结果处理时要转成小数来除防止精度丢失,最后向上取整;
  2. 从家到学校的时间(小时部分),通过整除计算取得;从家到学校的时间(分钟部分),通过取模计算取得;
  3. 根据从家到学校的时间(分钟部分)是否为00,决定小时部分是否需要多减11。
C++
#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;
}
原文