HDU 1861 游船出租

/*******************************************************
 * @Nstd
 * 题号:HDU - 1861
 * 类型:水模拟
 * 题目:给出一些游船的借出和归还时间
 *           求借出的游船数量和平均时间
 *           只有借出没归还或只有归还没借出的信息去掉
 * 思路:结构提记录初始时间,并判断是否已借出
 *           读取的时候边记录边计算
 * 问题:没看清题意是平均借出时间,样例没出
 * 特例:无
 *
 *                                    —— 2012/3/19
 *******************************************************/

hdu - 1861
 1 #include <stdio.h>
2 #include <iostream>
3 #include <string.h>
4 #include <algorithm>
5 using namespace std;
6
7 #define N 105
8 #define cls(a) memset(a, 0, sizeof(a))
9
10 struct boat{
11 int sh, sm;
12 int f;
13 }bt[N];
14
15 int main()
16 {
17 int n, k, i, j, h, m, cnt, mtime;
18 char ch[2];
19
20 while(1)
21 {
22 cnt = mtime = 0;
23 cls(bt);
24 while(scanf("%d", &k)!=EOF && ~k)
25 {
26 scanf("%s%d:%d", ch, &h, &m);
27 if(!k) break;
28 if(ch[0] == 'S')
29 {
30 bt[k].sh = h;
31 bt[k].sm = m;
32 bt[k].f = 1;
33 }
34 else
35 {
36 if(bt[k].f)
37 {
38 bt[k].f = 0;
39 cnt++;
40 mtime += ((h-bt[k].sh)*60 + (m-bt[k].sm));
41 }
42 }
43 }
44 if(!~k) break;
45 printf("%d %d\n", cnt, cnt?((int)(1.0*mtime/cnt+0.5)):(0));
46 }
47 return 0;
48 }



原文地址:https://www.cnblogs.com/Nstd/p/2406016.html