终于做对一道可以写题解的题了!
首先,可以为了方便把时间转为分钟。
设分钟单位的结果为 ,结果的小时为 ,分钟为 。
然后,本题虽然单位都是20分钟,但由于高峰期的堵车,所以单位最多是 分钟,也就是每计算一次走 分钟或(在堵车时)走 分钟。
接着,半夜开车(样例 )时为了防止过午夜出现 点,所以需要 。
最后,不要忘记必须两位,可以使用 printf 函数的 “%02d” 等格式化,或者 cout 的 cout << setfill('0') << setw(2);
。
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(void){
int a,b;
scanf("%lld:%lld",&a,&b);
int c=60*a+b;
for(int i=1;i<=12;i++){
if(c>=420&&c<600)c+=20;
else if(c>=900&&c<1140)c+=20;
else c+=10;
}
printf("%02lld:%02lld",(c/60)%24,c%60);
return 0;
}