zoukankan      html  css  js  c++  java
  • *分支-12. 计算火车运行时间

      1 /*
      2  * Main.c
      3  * B12-分支-12. 计算火车运行时间
      4  *  Created on: 2014年6月4日
      5  *      Author: Boomkeeper
      6  *
      7  ********测试未通过*******
      8  */
      9 #include <stdio.h>
     10 #include <stdlib.h>
     11 
     12 int startTime,arrTime;
     13 int *p_startTime=&startTime;
     14 int *p_arrTime=&arrTime;
     15 
     16 /*将输入时间全部转化成分钟,再做时间差,算出运行的分钟数*/
     17 int changeMinute(int *time)
     18 {
     19     //printf("
    now changMinute() starting...
    ");
     20     int hour,minute,newtime;
     21 
     22     hour=*time/100;
     23     minute=*time%100;
     24     newtime=hour*60+minute;
     25     //printf("now changeMinute() is closing...
    ");
     26     return newtime;
     27 }
     28 
     29 /*将运行时间(分钟数)再转成hh:mm形式*/
     30 void changeHour(int *runTime)
     31 {
     32     //printf("
    now changeHour() is starting...
    ");
     33     int runTimeHour,runTimeMinute;
     34 
     35     runTimeHour=*runTime/60;
     36     //printf("runTimeHour = %i
    ",runTimeHour);
     37     runTimeMinute=*runTime-runTimeHour*60;
     38     //printf("runTimeMinute = %i
    ",runTimeMinute);
     39 
     40     printf("%02i:%02i
    ",runTimeHour,runTimeMinute);
     41     //printf("now changeHour() is closing...
    ");
     42 }
     43 
     44 /*如果没有跨过半夜12点*/
     45 void inOneDay()
     46 {
     47     //printf("
    now inOneDay() is starting ...
    ");
     48     int startTimeMinute=changeMinute(p_startTime);
     49     //printf("startTimeMinute = %i
    ",startTimeMinute);
     50     int arrTimeMinute=changeMinute(p_arrTime);
     51     //printf("arrTimeMinute = %i
    ",arrTimeMinute);
     52     int runtime=arrTimeMinute-startTimeMinute;
     53     //printf("
    runtime in minute = %i
    ",runtime);
     54     int *runTime=&runtime;
     55 
     56     changeHour(runTime);
     57     //printf("now inOneDay() is closing ...
    ");
     58 
     59 }
     60 
     61 /*如果跨过半夜12点*/
     62 void inTwoDay()
     63 {
     64     //printf("
    now inTwoDay() is starting ...
    ");
     65     int startTimeMinute=changeMinute(p_startTime);
     66     //printf("startTimeMinute = %i
    ",startTimeMinute);
     67     int arrTimeMinute=changeMinute(p_arrTime);
     68     //printf("arrTimeMinute = %i
    ",arrTimeMinute);
     69     int runtime=24*60-(startTimeMinute-arrTimeMinute);
     70     //printf("
    runtime in minute = %i
    ",runtime);
     71     int *runTime=&runtime;
     72 
     73     changeHour(runTime);
     74     //printf("now inTwoDay() is closing ...
    ");
     75 }
     76 
     77 /*判断输入数据的合法性*/
     78 void judge(int *p_startTime,int *p_arrTime)
     79 {
     80     //printf("now judge() is starting...
    ");
     81     if(*p_startTime<0 || *p_startTime>2359)
     82         exit(0);
     83     if(*p_arrTime<0 || *p_arrTime>2359)
     84         exit(0);
     85     if(*p_startTime == *p_arrTime)
     86     {
     87         printf("24:00
    ");//这里到底算不算在同一天内?不管怎么改,测试结果仍一样
     88         exit(0);
     89     }
     90     if(*p_startTime > *p_arrTime)
     91         inTwoDay();
     92     else
     93         inOneDay();
     94     //printf("now judge() is closing...
    ");
     95 }
     96 
     97 int main()
     98 {
     99     scanf("%4i %4i",p_startTime,p_arrTime);
    100     //printf("get startTime=%i,arrTime=%i
    
    ",*p_startTime,*p_arrTime);
    101 
    102     judge(p_startTime,p_arrTime);
    103 
    104     return 0;
    105 }

  • 相关阅读:
    [转载] c++ cout 格式化输出浮点数、整数及格方法
    [转]
    _jobdu_1001
    关于网页授权的两种scope的区别说明
    CentOS编译安装Python3
    Apache+OpenSSL实现证书服务器提供HTTPS
    Linux下安装Tomcat服务器和部署Web应用
    记一次肉机事件--yam
    通过关闭 UseDNS和GSSAPIAuthentication选项加速 SSH登录
    Git 系列之tag的用法---为你的代码标记版本号
  • 原文地址:https://www.cnblogs.com/boomkeeper/p/B12.html
Copyright © 2011-2022 走看看