zoukankan      html  css  js  c++  java
  • 计算火车运行的时间

    根据火车的出发时间和到达时间,编写程序计算整个旅途所用的时间。比如G198次列车从青岛站出发时间为16:00,到达北京南站的时间为20:40,则整个旅途所用时间为04:40。输入格式仅一行,包含两个4位的正整数start和end,中间以空格分隔,分别表示火车的出发时间和达到时间。在一行中输出整个旅途所用的时间,格式为“hh:mm”,其中hh表示2位小时数,mm表示2位分钟数。

    java显示:

    public class time {
    
        public static void main(String[] args) {
             int start,end;
             int hour,minute;
             Scanner in=new Scanner(System.in);
             start=in.nextInt();
             end=in.nextInt();
             start=start/100*60+start%100;
             end=end/100*60+end%100;
             hour=(end-start)/60;
             minute=(end-start)%60;
             System.out.println(hour+":"+minute);
        }
    }

    C显示:

    #include <stdio.h>
    int main(void) {
        int start, end;
        int hour, minute;
        scanf("%d%d", &start, &end);
        start = start / 100 * 60  + start % 100;
        end = end / 100 * 60 + end % 100;
        hour = (end - start) / 60;
        minute = (end - start) % 60;
        printf("%02d:%02d
    ", hour, minute);         
        return 0;
    }
  • 相关阅读:
    luogu P1340 兽径管理
    luogu P2828 Switching on the Lights(开关灯)
    luogu P1462 通往奥格瑞玛的道路
    codevs 2596 售货员的难题
    luogu P1145 约瑟夫
    luogu P1395 会议
    luogu P1041 传染病控制
    luogu P1198 [JSOI2008]最大数
    codevs 1191 数轴染色
    [POJ1082]Calendar Game
  • 原文地址:https://www.cnblogs.com/sunli0205/p/6056244.html
Copyright © 2011-2022 走看看