P5707 【深基2.例12】上学迟到 90分求解答

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

buzhiwuyu @ 2023-11-06 23:22:57

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

by 2323464216ab @ 2023-11-07 00:36:09

t=(s/t)加1是不是要加个条件,刚好除尽的情况下+1会出错


by buzhiwuyu @ 2023-11-07 16:57:24

@2323464216ab 确实是这样的!十分感谢你!


|