那位大佬帮帮蒟蒻……

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

这次是6个点了QAQ 3、5、7、8、9、10 ``` #include<bits/stdc++.h> using namespace std; int main(){ //freopen("ceshi.in","r",stdin); //freopen("ceshi.out","w",stdout); int s,v,h,m,hh,mm; cin>>s>>v; if (s%v==0){ m=s/v; } else{ m=s/v+1; } m+=10; if (m%60==0){ h=m/60; } else{ h=m/60+1; } while (m>=60){ m-=60; } hh=8-h; if (hh<0){ hh+=24; } mm=60-m; if (hh==0){ cout<<"00:"; } if (hh>0 || hh<10){ cout<<"0"<<hh<<":"; } if (hh>=10){ cout<<hh<<":"; } cout<<mm; } ```
by 易言九鼎 @ 2022-08-19 06:45:14


@[易言九鼎](/user/157873) 对于输入 `50 1`,您的代码输出 `07:60`,问题出在 `mm = 60 - m;`,当 $m = 0$ 时,需要特殊处理。
by metaphysis @ 2022-08-19 07:47:32


``` #include<bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int s, v, h, m, hh, mm; cin >> s >> v; m = s / v + (s % v != 0) + 10; h = 8 - (m / 60 + (m % 60 != 0)); m %= 60; cout << setw(2) << setfill('0') << (h < 0 ? h + 24 : h); cout << ':'; cout << setw(2) << setfill('0') << (m ? 60 - m: m) << endl; } ```
by metaphysis @ 2022-08-19 07:57:21


**这道题有好几个坑点,我先说说我的~~失败~~成功经验** **1.** 数据是49 1时,答案是**07:01**,注意**分钟**和**小时**都要**判断加不加前导零** **2.** 数据是50 1时答案是**07:00而不是06:60** **3.** 不要忘记那位yyy~~捡垃圾吃~~垃圾分类的**10分钟**!!! ------------ ~~浅浅的吐槽一下,yyy是什么鬼名字啊,还不如叫小明呢~~
by zbhujiaqi @ 2022-08-19 09:17:23


AC代码如下(c++) ```c #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> using namespace std ; const int S = 10001 ; int main () { int s , v ; scanf("%d%d" , &s , &v ) ; s += v - 1 ; int ans = 10 + s / v ; int hour = 0 ; if(ans >= 60 ) { hour = ans / 60 ; ans = ans % 60 ; } hour = 7 - hour ; ans = 60 - ans ; if(ans == 60) { hour ++ ; ans = 0 ; } if(hour < 0 ) hour += 24 ; if(hour < 10 ) cout << '0' << hour << ":" ; else cout << hour << ":" ; if(ans == 0 ) cout << "00" ; else if(ans < 10) cout << '0' ; cout << ans ; return 0 ; } ```
by zbhujiaqi @ 2022-08-19 09:18:50


@[易言九鼎](/user/157873)
by zbhujiaqi @ 2022-08-19 09:19:19


@[zbhujiaqi](/user/371901) @[metaphysis](/user/333388) 感谢二位巨佬!!!
by 易言九鼎 @ 2022-08-19 10:36:06


@[zbhujiaqi](/user/371901) yyy 是管理员
by JustinXiaoJunyang @ 2022-08-20 16:03:49


@[JustinXiaoJunyang](/user/397137) [~~我吓傻了~~] 《~~现在删了还来得及咩~~》
by zbhujiaqi @ 2022-08-20 17:04:25


|