分支-12. 计算火车运行时间(15)

来源:互联网 发布:围堰稳定性计算软件 编辑:程序博客网 时间:2024/04/25 10:13

分支-12. 计算火车运行时间(15)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
沈睿(浙江大学)

本题要求根据火车的出发时间和达到时间,编写程序计算整个旅途所用的时间。

输入格式:

输入在一行中给出2个4位正整数,其间以空格分隔,分别表示火车的出发时间和到达时间。每个时间的格式为2位小时数(00-23)和2位分钟数(00-59),假设出发和到达在同一天内。

输出格式:

在一行输出该旅途所用的时间,格式为“hh:mm”,其中hh为2位小时数、mm为2位分钟数。

输入样例:
1201 1530
输出样例:
03:29
import java.util.Scanner;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner in = new Scanner(System.in);int time1 = in.nextInt();int time2 = in.nextInt();int hh = time2/100-time1/100;int mm = time2%100-time1%100;if(mm<0){mm+=60;hh--;}System.out.print(hh>10?hh+":":"0"+hh+":");System.out.print(mm>10?mm:"0"+mm);}}


0 0
原创粉丝点击