Hdu 1861-cruise ship rental

Source: Internet
Author: User

Cruise ship rental
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
If you have an existing park cruise ship rental service, please write a charter management system. When a visitor charter a ship, the Administrator enters the ship number and presses the S key to start timing. When the visitor returns the ship, the Administrator enters the ship number and presses the E key to end timing. The ship number is a positive integer not greater than 100. When the Administrator enters 0 as the ship number, it indicates that the day of chartering is over. The system should output the number of chartering times and
Average time of chartering.
Note: Due to occasional line faults, there may be incomplete records, that is, the system should be able to automatically ignore such invalid records only when chartering is not done, or only when there is no chartering record.

 
Input
The test input contains several test cases. Each test case is a full-day Charter record in the format
Ship ID (1 ~ 100) key value (S or E) occurrence time (hour: minute)
Each day's record is guaranteed to be given in an ascending order of time. When the ship number is-1, all input ends, and the corresponding results are not output.

 
Output
Output one line for each test case, that is, the number of chartering times of tourists and the average chartering time of the day (precise to an integer time in minutes ).
 
Sample Input
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
1 S 08:20
2 S
1 E
0 E 17: 00
-1
Sample Output
2 196
0 0
1 60
Solution: define a struct array to save the rental time and status of each cruise ship, and then judge the input data of each group to determine whether the input data is valid, determine whether to charter or return the ship, and then find the time interval of the cruise ship rental represented by the valid data of each group until the end of the day, find the total time, divide by the total number of times.

# Include <stdio. h> # include <string. h> struct boat {int time; int flag;} a [105]; int count;/* record count */double sum;/* record time */int main () {int num, h, m; char c; sum = 0; count = 0; memset (a, 0, sizeof (a);/* initialize */while (1) {scanf ("% d", & num);/* ship ID */if (num =-1) break; getchar (); /* Space absorption */scanf ("% c", & c);/* chartering status */scanf ("% d: % d", & h, & m ); if (num = 0)/* day chartering ends */{if (count) printf ("% d %. lf \ n ", count, sum/count);/* returns the result rounded to */elseprintf (" 0 0 \ n "); sum = 0; count = 0; continue;} if (c ='s ') {a [num]. time = h * 60 + m; a [num]. flag = 1;} else {if (a [num]. flag)/* determine whether the ship has been rented out */{sum + = h * 60 + m-a [num]. time;/* obtain the total time of chartering */count ++;/* times */a [num]. flag = 0;/* indicates that the ship has been returned */} return 0 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.