what

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

```c #include<bits/stdc++.h> using namespace std; int main() { int n,m,x=10;//10(倒垃圾的时间) cin>>n>>m;//读入 x+=n/m; if(n%m!=0) x++; if(x<=480) x=480-x;//如果在当天8时减去用时 else x=1440-x+480;//否则减去当天时间用24时减 int a=x/60%24,b=x%60;//a:时,b:分 if(a<10)cout<<0;//加0 cout<<a<<":"; if(b<10) cout<<0;//加0 cout<<b; return 0; } //480(8时的分钟数) //1440(24时的分钟数) ```
by xQWQx @ 2023-08-24 20:41:01


是不是没考虑用时超过八小时的情况,即提前一天出发?
by glx123 @ 2023-08-24 20:41:27


@[wangjingtian1](/user/1004343) 这是我的代码,你先看一看,我帮你找找错在哪
by xQWQx @ 2023-08-24 20:41:50


``` #include<bits/stdc++.h> using namespace std; int main(){ double a,b; cin>>a>>b; int t=ceil(a/b)+10; int shi=t/60; int fen=t%60; int s=8,f=0; do{ s=s-shi; f=f-fen; if(s<0){ s=s+24; } if(f<0){ f=f+60; s--; } }while(f<0||s<0); if(s<10){ cout<<0; } cout<<s<<":"; if(f<10){ cout<<0; } cout<<f; return 0; } ```
by glx123 @ 2023-08-24 20:42:49


@[wangjingtian1](/user/1004343) 你没有考虑到提前一天出发的情况
by xQWQx @ 2023-08-24 20:44:17


``` #include <bits/stdc++.h> using namespace std; int main(){ int s,v; cin>>s>>v; int z=s/v; int quyu=s%v; if(quyu!=0){ z++; } int time1=480-10; int time2=(time1-z+60*24)%(60*24); if(time2/60<10){ cout<<"0"<<time2/60; }else{ cout<<time2/60; } cout<<":"; if(time2%60<10){ cout<<"0"<<time2%60; }else{ cout<<time2%60; } } ``` 即可
by glx123 @ 2023-08-24 20:47:00


|