C++,70分求助

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

```c #include <bits/stdc++.h> using namespace std; double s,v,m; int n,a,t,b; int main(){ cin>>s>>v; n = 8 * 60 + 24 * 60; t = ceil(s / v) + 10; n = n - t; if(n >= 24 * 60){ n -= 24 * 60; } b = n % 60; a = n / 60; if(a < 10){ if(b < 10){ cout<<"0"<<a<<":0"<<b; } else{ cout<<"0"<<a<<":"<<b; } } else{ if(b < 10){ cout<<a<<":0"<<b; } else{ cout<<a<<":"<<b; } } return 0; } ```
by Li_mz__ @ 2022-10-25 17:42:58


嗯,分钟也要判断小于0,然后就只错了一个点,应该是逻辑有点问题,我再看看 @[Xunj4](/user/755849)
by WZRYWZWY @ 2022-10-25 18:14:34


把while(h<=0)改成<就可以了 min--;的位置应该要提前 ```cpp #include <iostream> using namespace std; int main() { int s, v,t,min=0,h=8; cin >> s >> v; t = s / v; if(s%v!=0) t++; t += 10; while (t) { min--; if(min<0){ min += 60; h--; } t--; } while (h<0) { h = 24 + h; } if (h<10) { cout << 0; } cout << h << ':'; if (min < 10)cout << 0; cout << min; } ``` @[Xunj4](/user/755849)
by WZRYWZWY @ 2022-10-25 18:42:21


@[WZRYWZWY](/user/704668) 谢谢
by 0xf000 @ 2022-10-27 16:45:26


|