码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-06-02 10:59:05      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   code   java   a   

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

输入格式:

输入在一行中给出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) {
		Scanner cin = new Scanner(System.in);
		int a = cin.nextInt();
		int b = cin.nextInt();
		int c = b - a;
		if (b % 100 < a % 100) {
			System.out.printf("%02d:%02d", c / 100, c % 100 - 40);
		} else {
			System.out.printf("%02d:%02d", c / 100, c % 100);
		}
	}
}

分支-12. 计算火车运行时间(15),布布扣,bubuko.com

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

标签:c   style   class   code   java   a   

原文地址:http://blog.csdn.net/ofengwuyu1/article/details/28091959

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!