题解:P5707 【深基2.例12】上学迟到
Iron_Spade · · 题解
Solution
- 前置知识:顺序结构、取模。
给定路程
由于我们要在一个整分钟时刻出发,所以我们计算时间时需要对分钟向上取整。
又因为时间可能会提前到前一天,所以我们首先对
#include<bits/stdc++.h>
#define ll long long
using namespace std;
double s,v,m;
int n,ans1,ans2,t;
double read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x *= 10,x += c - '0';
c = getchar();
}
return x * f;
}
int main() {
s = read();
v = read();
n = 8 * 60 + 24 * 60;
t = ceil(s / v) + 10;
n -= t;
if(n >= 1440) n -= 1440;
ans1 = n % 60;
ans2 = n / 60;
if(ans2 < 10) {
if(ans1 < 10) cout << "0" << ans2 << ":0" << ans1;
else cout << "0" << ans2 << ":" << ans1;
}
else {
if(ans1 < 10) cout << ans2 << ":0" << ans1;
else cout << ans2 << ":" << ans1;
}
return 0;
}