题目1022:游船出租(结构体使用)
题目链接:http://ac.jobdu.com/problem.php?pid=1022
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
// // 1022 游船出租.cpp // Jobdu // // Created by PengFei_Zheng on 29/04/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <cstring> #include <cmath> #define MAX_SIZE 101 using namespace std; struct Boat{ int id; int start; int time; bool rent; Boat(){ time = 0; rent = false; } }; Boat boat[MAX_SIZE]; int num; char key; int hour,minute; int rentCount; double totalTime; int main(){ // freopen("/Users/pengfei_zheng/Desktop/input.txt", "r", stdin); while(scanf("%d",&num)!=EOF && num!=-1){ rentCount = totalTime = 0; while(num != 0){ scanf(" %c %d:%d",&key,&hour,&minute); if(key == 'S'){ boat[num].id = num; boat[num].start = hour * 60 + minute; boat[num].rent = true; } else if(key == 'E'){ if(boat[num].rent == true){ boat[num].time = (hour * 60 + minute) - boat[num].start; rentCount++; totalTime += boat[num].time; } } scanf("%d",&num); } scanf(" %c %d:%d",&key,&hour,&minute); if(rentCount!=0){ printf("%d %.0f\n",rentCount,totalTime/rentCount); } else{ printf("0 0\n"); } } } /************************************************************** Problem: 1022 User: zpfbuaa Language: C++ Result: Accepted Time:0 ms Memory:1520 kb ****************************************************************/
作者: 伊甸一点
出处: http://www.cnblogs.com/zpfbuaa/
本文版权归作者伊甸一点所有,欢迎转载和商用(须保留此段声明),且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文链接 如有问题, 可邮件(zpflyfe@163.com)咨询.