P5707 【深基2.例12】上学迟到
题目描述
yyy 的学校要求早上 8 点前到达。学校到 yyy 的家一共有 s(s≤10000)s(s\le 10000)s(s≤10000) 米,而 yyy 可以以 v(v<10000)v(v<10000)v(v<10000) 米每分钟的速度匀速走到学校。此外在上学路上它还要额外花 10 分钟时间进行垃圾分类。请问为了避免迟到 yyy 最晚什么时候出门?输出 HH:MM 的时间格式,不足两位时补零。由于路途遥远, yyy 可能不得不提前一天出发,不过不可能提前超过一天。
输入格式
两个正整数 s,v,意思已经在题目中给定。
输出格式
hh:mm 表示最晚离开家的时间(时:分,必须输出两位,不足两位前面补0)
输入输出样例
输入 #1
100 99
输出 #1
07:48
import java.util.Scanner;
/**
* @Author SouthWind
* @Date 2021/6/23 14:22
*/
public class go_school {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();
int v = sc.nextInt();
int x1 = 7 , x2 = 60;
float a = s / (float) v;
float b = a - (int) a ;
int t0 = (int)a;
if(a>470){
x1 += 24; //24+7
}
if(b != 0){ //考虑所用时间不是整数的情况。
t0++;
}
int t1 = 0;
if(t0>59){ //考虑时间在一个小时以上
t1 = t0 / 60; //7.85---7 -0
t0 = t0 % 60; //51 -51
}
if(t0>50){ //现在的时间已经不会超过一个小时了,但是得考虑大于49分钟的情况。
t1 ++; //8 -1
// System.out.println("t1:" + t1);
t0 = t0 - 60; //1 -1
}
x1 = x1 - t1; //24 -6
x2 = x2 - t0; //9 -59
//需要分开讨论。
if(x2 == 60){
x1++;
x2 = 0;
}
if(x2<10){
x1 -= 1;
x2 += 50;
}else {
x2 -= 10;
}
if(x2<10 && x1 <10){ //08:08
System.out.println("0" + x1 + ":" + "0" + x2);
}
else{
if(x2>9 && x1 >9){ //12:30
System.out.println(x1 + ":" + x2);
}else {
if(x2>9 && x1 <9){
System.out.println( "0" + x1 + ":" + x2);
}else{
System.out.println(x1 + ":" + "0" + x2);
}
}
}
}
}