求助!

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

NachoDoritosLOL @ 2024-06-06 06:47:12

求助各路大佬!!!\ 我运行的样例不对,请求帮助!

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int s,v,h=0,m=0;
    cin>>s>>v;
    m=s/v;
    m+=10;
    m=8*60-m;
    if(m<0){
        m=abs(m)+20*60;
    }
    h=m%60;
    m/=60;
    if(m<10){
        if(h<10){
            cout<<0<<h<<":"<<0<<m;
        }
        else{
            cout<<h<<":"<<0<<m;
        }
    }
    else{
        if(h<10){
            cout<<0<<h<<":"<<m;
        }
        else{
            cout<<h<<":"<<m;
        }
    }
    return 0;
}

by _joker_r @ 2024-06-06 08:12:56

这是我的代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s,v,t,a,h,m;
    cin>>s>>v;
    t=ceil(s*1.0/v);
    a=(480+2880-10-t)%1440;
    h=a/60;
    m=a%60;
    if(h<10)
    cout<<0;
    cout<<h<<":";
    if(m<10)
    cout<<0;
    cout<<m;
 } 

by _joker_r @ 2024-06-06 08:14:25

结果


by _joker_r @ 2024-06-06 08:23:16

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int s,v,h=0,m=0;
    cin>>s>>v;
    m=ceil(s*1.0/v);
    m+=10;
    m=8*60-m;
        m=m+24*60;
        m%=1440;
    h=m%60;
    m/=60;
    if(h<10){
        if(m<10){
            cout<<0<<m<<":"<<0<<h;
        }
        else{
            cout<<m<<":"<<0<<h;
        }
    }
    else{
        if(m<10){
            cout<<0<<m<<":"<<h;
        }
        else{
            cout<<m<<":"<<h;
        }
    }
    return 0;
}

by _joker_r @ 2024-06-06 08:25:51

首先,你的m与h搞反了。其次,你的m要向上取整。再次,m要模24*60,这样如果m大于一天就可以减去一天。


by NachoDoritosLOL @ 2024-06-06 22:11:53

@zhizhenzhenzihao 谢谢


|