Question: 5. Write a C++ program (or Java program) called hw1_2.cpp (or hw1_2.java) that reads the time information of events in a convention center and displays

5. Write a C++ program (or Java program) called hw1_2.cpp (or hw1_2.java) that reads the time information of events in a convention center and displays the maximum number of concurrent events in the convention center.

Input format: This is a sample input from a user.

3

6 11

14 20

13 17

The first number (= 3 in the example) indicates that there are three event in the convention center. Then, the following lines are the time information (= start and ending hours) of each event. For example, the second line 6 11 indicates that there is an event which starts at 6:00(AM) and finishes at 11:00(AM). The next line indicates that there is an event from 2:00(PM) (= 14:00) to 8:00(PM) (= 20:00). The last event is from 1:00(PM) to 5:00(PM). In the homework, you should display the maximum number of events that can occur at the same time. For the input, your result should be 2 because the second and third events will happen at the same time from 2:00(PM) to 5:00(PM). For the homework, you can assume that the hour information always uses a positive integer from 0 to 23.

Sample Run 1: Assume that a user typed the following lines

3

6 11

14 20

13 17

This is the correct output.

Answer:2

Sample Run 2: Assume that a user typed the following lines

4

10 15

10 12

9 10

8 9

This is the correct output. Note that there are three events at 10:00(AM).

Answer:3

Sample Run 3: Assume that a user typed the following lines

4

10 12

2 9

13 17

18 23

This is the correct output.

Answer:1

Hint: Pay attention to the starting and ending hours. Also, sorting and a counter will be useful.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!