上学迟到,不分情况讨论的思路
查看原帖
上学迟到,不分情况讨论的思路
1363991
NO0417楼主2024/5/24 19:14

**题解思想:**题中不超过一天,前一天8点当成0点整,那么现在的8点,就距离24*60分钟,减去花费的时间t,也就是距离前一天8点的分钟,除以60得到小时需要加上8,才是真实小时,考虑到超过24h,因此还得%24,而分钟不受影响

#include<bits/stdc++.h>
using namespace std;

int main(){
    int s,v,t,h,m;
    cin>>s>>v;
    t = ceil(s*1.0/v)+10;
    h = ((24*60-t)/60+8)%24;
    m = (24*60-t)%60;
    if(h<10){
        cout<<0<<h<<":";
    }else{
        cout<<h<<":";
    }
    if(m<10){
        cout<<0<<m;
    }else{
        cout<<m;
    }
    return 0;
}
2024/5/24 19:14
加载中...