全部评论
求大佬贴代码
从公交出第一个站的那一刻才开始计时,所以第一圈回到原点只用花15*2+10=40分钟,接下来再回到原点才需要15*3=45分钟Orz
没错,因为你不会再初始站呆5分钟,而是直接走
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
String[] a = in.nextLine().split(",");
int one, sum, jl, qs, zd, q, w;
int xs, fen, xs2, fen2;
one = Integer.parseInt(a[0]);
if (one < 3 || !isValidDate(a[1]) || !isValidDate(a[2])) {
System.out.println("incorrect data");
} else {
sum = one * 15;
xs = Integer.parseInt(a[1].substring(11, 13));
fen = Integer.parseInt(a[1].substring(14, 16));
xs2 = Integer.parseInt(a[2].substring(11, 13));
fen2 = Integer.parseInt(a[2].substring(14, 16));
jl = (xs2 - xs) * 60 + fen2 - fen;
qs = jl / sum + 1;
zd = jl % sum;
int which15 = (zd % 15==0)?zd/15:(zd/15+1) ;
q = (which15 == one) ? 1 : (which15 + 1);
w = (which15 == one) ? q : (zd % 15 == 0) ? q : (q + 1);
System.out.println(qs + ";" + q + "-" + w);
}
}
public static boolean isValidDate(String str) {
boolean convertSuccess = true;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
format.setLenient(false);
format.parse(str);
} catch (ParseException e) {
convertSuccess = false;
}
return convertSuccess;
}
}
相关推荐
10-25 11:03
上海理工大学 Python 点赞 评论 收藏
分享