zoukankan      html  css  js  c++  java
  • L1-043 阅览室

    天梯图书阅览室请你编写一个简单的图书借阅统计程序。当读者借书时,管理员输入书号并按下S键,程序开始计时;当读者还书时,管理员输入书号并按下E键,程序结束计时。书号为不超过1000的正整数。当管理员将0作为书号输入时,表示一天工作结束,你的程序应输出当天的读者借书次数和平均阅读时间。

    注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有S没有E,或者只有E没有S的纪录,系统应能自动忽略这种无效纪录。另外,题目保证书号是书的唯一标识,同一本书在任何时间区间内只可能被一位读者借阅。

    输入格式:

    输入在第一行给出一个正整数N(10),随后给出N天的纪录。每天的纪录由若干次借阅操作组成,每次操作占一行,格式为:

    书号([1, 1000]内的整数) 键值SE) 发生时间hh:mm,其中hh是[0,23]内的整数,mm是[0, 59]内整数)

    每一天的纪录保证按时间递增的顺序给出。

    输出格式:

    对每天的纪录,在一行中输出当天的读者借书次数和平均阅读时间(以分钟为单位的精确到个位的整数时间)。

    输入样例:

    3
    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
    

    输出样例:

    2 196
    0 0
    1 60
    
     
    闲来无事来填个坑,这道水题略坑,直接讨论操作以及书被借的状态就行,具体四舍五入以及刷新最后借书时间的问题,看注释......
     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<map>
     7 #include<set>
     8 #include<vector>
     9 using namespace std;
    10 #define ll long long 
    11 #define dd cout<<endl
    12 const int inf=99999999;
    13 const int mod=1e9+7;
    14 const int maxn=1e3+7;
    15 map<int,char>book;//标记书的状态 
    16 map<int,int>Time;//标记时间 
    17 int main()
    18 {
    19     int n;
    20     scanf("%d",&n);
    21     int hours,mins; 
    22     for(int i=0;i<n;i++)
    23     {
    24         book.clear();//每次使用之前先清空容器,养成好习惯
    25         Time.clear(); 
    26         int id,hours,mins;
    27         char op;
    28         double count_jie=0;//用double解决四舍五入问题 
    29         double count_Time=0;
    30         while(scanf("%d %c %d:%d",&id,&op,&hours,&mins)!=EOF)
    31         {
    32             if(id==0)
    33                 break;//结束一天标志 
    34             if(book[id]==0)//等于0说明为空 
    35             {
    36                 if(op=='E')
    37                     continue;//还没借书直接还书,直接忽略 
    38                 else if(op=='S')//借书 
    39                 {
    40                     book[id]=op;
    41                     Time[id]+=(hours*60+mins);
    42                 }
    43             }
    44             else if(book[id]=='S')
    45             {
    46                 if(op=='S')
    47                 {
    48                     Time[id]=(hours*60+mins);//注意这里要刷新借书时间,有关于测试点1
    49                     continue;
    50                 }
    51                 else if(op=='E')
    52                 {
    53                     count_jie++;
    54                     count_Time+=(hours*60+mins-Time[id]);
    55                     Time[id]=0;//还完书重置标记 
    56                     book[id]=0;
    57                 }
    58             }    
    59         }
    60         if(count_jie==0)
    61             printf("0 0
    ");
    62         else
    63              printf("%.0lf %.0lf
    ",count_jie,(count_Time+0.5)/count_jie);
    64     }
    65     return 0;
    66 }
    大佬见笑,,
  • 相关阅读:
    自定义滚动条jQuery插件- Perfect Scrollbar
    js遍历for,forEach, for in,for of
    jQuery中$.extend(true,object1, object2);深拷贝对象
    使用遍历的方法实现对对象的深拷贝
    'NSUnknownKeyException' this class is not key value coding-compliant for the key XXX
    NSInternalInconsistencyException: loaded the "XXXView" nib but the view outlet was not set
    HTTP && socket
    stackview
    233. Number of Digit One *HARD* -- 从1到n的整数中数字1出现的次数
    231. Power of Two 342. Power of Four -- 判断是否为2、4的整数次幂
  • 原文地址:https://www.cnblogs.com/xwl3109377858/p/10346611.html
Copyright © 2011-2022 走看看