码迷,mamicode.com
首页 > 其他好文 > 详细

题目1022:游船出租(结构体使用)

时间:2017-04-29 19:52:29      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:min   log   UI   open   art   stdio.h   string   ted   oat   

题目链接: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
****************************************************************/

 

题目1022:游船出租(结构体使用)

标签:min   log   UI   open   art   stdio.h   string   ted   oat   

原文地址:http://www.cnblogs.com/zpfbuaa/p/6785912.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!