L1-043 阅览室 (20 分)

天梯图书阅览室请你编写一个简单的图书借阅统计程序。当读者借书时,管理员输入书号并按下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 <cstdlib>
 4 #include <cstring>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <cmath>
 8 #include <queue>
 9 #include <set> 
10 #include <map>
11 using namespace std;
12 #define  pi acos(-1.0)
13 typedef long long ll;
14 int n;
15 int num,hh,mm;
16 char c,cc;
17 struct Node{
18     int h,m;
19 };
20 set<int>se;
21 map<int,Node>mp;
22 int main()
23 {
24     scanf("%d",&n);
25     int cnt=0,ans=0;
26     while(~scanf("%d",&num)){
27         cin>>c;
28         if(num==0){
29                 scanf("%02d:%02d",&hh,&mm);                
30                 int f=round(ans*1.0/cnt);//没特殊说明就是四舍五入
31                 if(ans==0) f=0;
32                 printf("%d %d\n",cnt,f);
33                 se.clear();
34                 ans=0,cnt=0;
35                 continue;//不然会继续执行下面的语句。 
36         }
37         if(c=='S') //同一本书在任何时间区间内只可能被一位读者借阅
38         {
39                 scanf("%02d:%02d",&mp[num].h,&mp[num].m);        
40                 se.insert(num);        
41         }
42         if(c=='E'){
43         scanf("%02d:%02d",&hh,&mm);
44         if(se.count(num)==1){
45             cnt++;
46             se.erase(num);//还已经还过的书。 
47             ans+=(hh*60+mm)-(mp[num].h*60+mp[num].m);    
48         }        
49     }
50     }
51     return 0;
52 }

 

 

posted on 2019-03-13 21:24  cltt  阅读(461)  评论(0编辑  收藏  举报

导航