zoukankan      html  css  js  c++  java
  • 分支-12. 计算火车执行时间(15)

    本题要求依据火车的出发时间和达到时间,编敲代码计算整个旅途所用的时间。

    输入格式:

    输入在一行中给出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);
    		}
    	}
    }
    

  • 相关阅读:
    活动安排问题
    完美字符串
    Codeforces Round #696 (Div. 2) 解题报告
    Codeforces 1459D
    Codeforces 25D
    POJ 1847
    LightOJ 1074
    POJ 3159
    POJ 1511
    POJ 1502
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4031700.html
Copyright © 2011-2022 走看看