游船出租

题目描述:
    现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下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 <iostream>
  2 #include <cstdio>
  3 #include <cstdlib>
  4 #include <cmath>
  5 #include <cctype>
  6 #include <cstring>
  7 
  8 #include <vector>
  9 #include <deque>
 10 #include <list>
 11 #include <map>
 12 #include <set>
 13 #include <stack>
 14 #include <queue>
 15 #include <algorithm>
 16 #include <string>
 17 
 18 
 19 
 20 using namespace std;
 21 
 22 
 23 int vis[101];
 24 
 25 
 26 struct Re{
 27     int id;
 28 
 29     char s[100];
 30     char e[100];
 31 }re[101];
 32 
 33 
 34 
 35 
 36 int main()
 37 {
 38 
 39 
 40     int i,j,k;
 41 
 42     int id;
 43 
 44 
 45     char s[100],e[100];
 46 
 47 
 48 
 49 char tag;
 50 
 51 
 52     while(scanf("%d",&id)!=EOF)
 53     {
 54         if(id==-1)
 55             break;
 56 
 57         getchar();
 58 
 59 
 60         for(i=1;i<=100;i++)
 61             vis[i]=0;
 62 
 63         int num=0;
 64 
 65         double st=0;
 66 
 67 
 68 
 69         
 70 
 71 
 72         scanf("%c %s",&tag,s);
 73         getchar();
 74 
 75         if(tag=='S')
 76         {vis[id]=1;strcpy(re[id].s,s);}
 77         else
 78         {
 79             if(vis[id]==1)
 80             {vis[id]=2;strcpy(re[id].e,s);
 81             
 82             
 83             num++;
 84             char temps[100];
 85 
 86             int tt=0;
 87 
 88             int hh,mm;
 89 
 90 
 91 
 92             strcpy(temps,re[id].s);
 93 
 94             sscanf(temps,"%d:%d",&hh,&mm);
 95 
 96             tt=hh*60+mm;
 97 
 98             strcpy(temps,re[id].e);
 99 
100             sscanf(temps,"%d:%d",&hh,&mm);
101 
102 
103             tt=hh*60+mm-tt;
104 
105 
106             
107 
108             st+=tt;
109 
110 
111 
112 
113 
114             
115             
116             
117             }
118         }
119 
120         
121 
122         if(id==0)
123         {cout<<0<<' '<<0<<endl;continue;}
124 
125 
126 
127 
128         while(scanf("%d %c %s",&id,&tag,s)!=EOF)
129         {
130             if(id==0)
131                 break;
132 
133         if(tag=='S')
134         {vis[id]=1;strcpy(re[id].s,s);}
135         else
136         {
137             if(vis[id]==1)
138             {vis[id]=2;strcpy(re[id].e,s);
139             
140             num++;
141             char temps[100];
142 
143             int tt=0;
144 
145             int hh,mm;
146 
147 
148 
149             strcpy(temps,re[id].s);
150 
151             sscanf(temps,"%d:%d",&hh,&mm);
152 
153             tt=hh*60+mm;
154 
155             strcpy(temps,re[id].e);
156 
157             sscanf(temps,"%d:%d",&hh,&mm);
158 
159 
160             tt=hh*60+mm-tt;
161 
162         
163 
164             st+=tt;
165 
166 
167             
168             
169             
170             }
171         }
172 
173         }
174 
175 
176 
177         st/=num;
178 
179 
180         printf("%d %.0lf\n",num,st);
181         }
182 
183         
184 
185         
186 
187 
188 
189     return 0;
190 }

 

posted @ 2012-05-30 20:27  cseriscser  阅读(256)  评论(0编辑  收藏  举报