题目1022:游船出租
2013-04-11 13:58
183 查看
/* 题目描述: 现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下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 * */ #include <cstdio> #include <cstring> #include <set> #include <iostream> #include <cmath> using namespace std; const int N = 60; struct Info { int no; int start; bool operator == (const Info &b)const { return no == b.no; } bool operator < (const Info &b)const { return no < b.no; } }; struct Result { int no; int t; bool operator < (const Result &b)const { return no < b.no; } }; int main() { char buf ; #ifndef ONLINE_JUDGE freopen("e:\\uva_in.txt", "r", stdin); #endif set<Info> s; set<Result> result; while (gets(buf) && strcmp(buf, "-1") != 0) { int no; char ch; char tmp ; Info info; sscanf(buf, "%d %c%s", &no, &ch, tmp); //cout << "no:" << no << " ch:" << ch << " tmp:" << tmp << endl; if (no != 0) { info.no = no; int hour, min; sscanf(tmp, "%d:%d", &hour, &min); set<Info>::iterator pos = s.find(info); if (pos == s.end()) { if (ch == 'S') { info.start = hour * 60 + min; s.insert(info); } } else { Result res; if (ch == 'E') { res.no = no; res.t = hour * 60 + min - pos->start; result.insert(res); } } } else { double ans = 0; for (set<Result>::iterator i = result.begin(); i != result.end(); i++) { ans += i->t; } printf("%d %d\n", result.size(), result.size()?(int)(ans / result.size() + 0.5):0); s.clear(); result.clear(); } } return 0; }
相关文章推荐
- 九度oj 题目1022:游船出租 【ZJU2007考研机试题3】
- 题目1022:游船出租 2007年浙江大学计算机及软件工程研究生机试真题
- 题目1022:游船出租
- 题目1022:游船出租
- 题目1022:游船出租
- 九度 Online Judge 算法 刷题 题目1022:游船出租
- 题目1022:游船出租
- 题目1022:游船出租
- 题目1022:游船出租
- 九度OJ 题目1022:游船出租
- 九度OJ 题目1022:游船出租
- 题目1022:游船出租
- 题目1022:游船出租
- 题目1022:游船出租(结构体使用)
- 题目1022:游船出租
- 题目1022:游船出租
- 九度OJ 1022:游船出租 (统计)
- 九度oj -1022-游船出租
- 九度OnlineJudge之1022:游船出租
- 2007浙大复试上机考试题目3--游船出租