samedi 17 octobre 2020

How to solve the following task in C++, if we are only allowed to use # include

I am new to programming and C++, so I would like to ask for help in a basic question. How can we implement the following task in C++?

Task:

A company lends a special machine to its U number of clients. For the next N day, a total order of M was received. Each order is an X Y number pair, which means that customer X orders a machine for day Y. Each customer can add up to one order for each day and only one customer can receive a machine for a given day. Write a program that calculates the number of

(a) the minimum number of machines the company must have to be able to take all orders;

(b) the days on which at least one machine was requested;

(c) customers who have requested machinery for most days;

(d) the start and end days of the maximum time interval during which at least one machine has been requested;

e) which are the two consecutive days for which most different customers have requested machines;

Requirements:

We are allowed to use the following input lines: # include and # include <stdblib.h>

The program should end with return 0;

In the input and output, the format is very important, it should exactly look like the given example, there should be a space between the numbers and lines should look like in the example. The program should not wait for any key to be pressed at the end, because it will run in an environment, like a test environment.

Input:

In the first line of standard input, there are three integers separated by a space, the number U of customers (1≤U≤500), the number N (2≤N≤300), and the number M of orders (1≤M≤U*N). The following line M contains an order, two numbers separated with a space: a customer's X serial number (1≤X≤U) and the Y number (1≤Y≤N) of the day. This means that customer X orders a machine for day Y.

Output:

The first line of the standard output should contain a whole number, the minimum number of machines required to satisfy all orders.

In the second line, the first number should be the number of the days on which at least one machine was ordered, followed by the serial numbers of these days in ascending order.

In the third line, the first number should be the number of customers who have requested a machine for most days, followed by the serial numbers of these customers in ascending order.

The fourth line should contain two whole numbers, the start and end days of the longest time interval, during which at least one machine was requested. If there are more solutions for this, we must print the one, that is earlier than the other.

In the fifth line, the first number should be the number of the first day of the two consecutive days that most different customers have requested. The second number in line is the number of customers. If there are multiple solutions, we need to print the lowest number.

Example:

Input:

5 10 8 // U N M

1 3 // X Y

2 2

5 2

2 3

3 4

2 8

5 3

5 7

Output:

3 // solution for part a

5 2 3 4 7 8 // solution for part b

2 2 5 // solution for part c

2 4 // solution for part d

3 4 // solution for part e

Thank you for any help. I would appreciate if the answer is more detailed and gives ideas for the algorithm and the implementing code, too.

Aucun commentaire:

Enregistrer un commentaire