50分求助

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

untiy @ 2024-07-25 19:38:17

#include <bits/stdc++.h>
using namespace std;
int s,v,time_l=8,time_r=0;
int jinzhi(int a,int b)
{
    if(a%b==0) return a/b;
    if(a%b!=0) return a/b+1;
}
int main()
{
    cin>>s>>v;
    int t=jinzhi(s,v)+10;//总共要几分钟 
    //cout<<t<<"\n";
    if(time_r-t<0)
    {
        if(t%60==0) //如果时间为60的倍数 
        {//没必要动分钟 
            if(t<60) time_l-=1;
            else time_l-=t/60;
        }
        if(t%60!=0)//如果不为60的倍数 
        {
            if(t<60) time_l-=1;
            else time_l-=t/60+1;//小时 
            time_r=60;
            time_r-=t%60;//分钟 
        }
    }
    if(time_l<10) cout<<0;
    cout<<time_l<<":"<<time_r;
    return 0;
}

by haimingbei @ 2024-07-25 19:44:16

@untiy 自己看看,要考虑的点挺多

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

|