• 九度oj 题目1022:游船出租


    题目描述:
        现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下S键,系统开始计时;当游客还船时,管理员输入船号并按下E键,系统结束计时。船号为不超过100的正整数。当管理员将0作为船号输入时,表示一天租船工作结束,系统应输出当天的游客租船次数和平均租船时间。
        注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有租船没有还船,或者只有还船没有租船的纪录,系统应能自动忽略这种无效纪录。
    输入:

        测试输入包含若干测试用例,每个测试用例为一整天的租船纪录,格式为:
        船号(1~100) 键值(S或E) 发生时间(小时:分钟)
        每一天的纪录保证按时间递增的顺序给出。当读到船号为-1时,全部输入结束,相应的结果不要输出。

    输出:
        对每个测试用例输出1行,即当天的游客租船次数和平均租船时间(以分钟为单位的精确到个位的整数时间)。
    样例输入:
    1 S 08:10
    2 S 08:35
    1 E 10:00
    2 E 13:16
    0 S 17:00
    0 S 17:00
    3 E 08:10
    1 S 08:20
    2 S 09:00
    1 E 09:20
    0 E 17:00
    -1
    样例输出:
    2 196
    0 0
    1 60

    代码如下:
     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <cstring>
     4 #include <string>
     5 #define MAX 202
     6 struct Time
     7 {
     8     int hour;
     9     int minute;
    10 };
    11 
    12 int boot[MAX];
    13 Time bootTime[MAX];
    14 // b - a
    15 int calTime(Time a, Time b) {
    16     int c = b.hour - a.hour;
    17     c = c * 60 + (b.minute - a.minute);
    18     return c;
    19 }
    20 
    21 int main(int argc, char const *argv[])
    22 {
    23     int bootNum;
    24     char bootState;
    25     Time timeTemp;
    26     //freopen("input.txt","r",stdin);
    27     scanf("%d",&bootNum);
    28     while(bootNum != -1) {
    29         int count = 0, timeCount = 0;
    30 
    31         for(int i = 0; i < MAX; i++) {
    32             boot[i] = 0;
    33         }
    34         while(bootNum != 0) {
    35             scanf("%c %d:%d",&bootState, &timeTemp.hour,&timeTemp.minute);
    36             if(bootState == 'S') {
    37                 bootTime[bootNum] = timeTemp;
    38                 boot[bootNum] = 1;
    39             }
    40             else if(bootState == 'E') {
    41                 if(boot[bootNum] == 1) {
    42                     count++;
    43                     timeCount = timeCount + calTime(bootTime[bootNum],timeTemp);
    44                     boot[bootNum] = 0;
    45                 }
    46             }
    47 
    48             scanf("%d",&bootNum);
    49         }
    50         scanf(" %c %d:%d",&bootState, &timeTemp.hour,&timeTemp.minute);
    51         if(count != 0) {
    52             printf("%d %.0lf
    ",count, (double)timeCount/(double)count);
    53         }
    54         else {
    55             printf("%d %d
    ",0,0);
    56         }
    57 
    58         scanf("%d",&bootNum);
    59     }    
    60     return 0;
    61 }
  • 相关阅读:
    wordpress站点更换域名了如何快速设置
    wordpress调用文章摘要,若无摘要则自动截取文章内容字数做为摘要
    宝塔https部署没成功的原因排查
    全球百大网站排行榜6月榜出炉
    深度 | 邢波教授谈人工智能科学路径:为人工智能装上「无穷动」引擎
    C++中public,protected,private派生类继承问题和访问权限问题
    谁再说Matlab速度慢,我跟谁急
    C++常用的#include头文件总结
    Visual Studio的调试技巧
    How to (seriously) read a scientific paper
  • 原文地址:https://www.cnblogs.com/jasonJie/p/5680762.html
Copyright © 2020-2023  润新知