C ++程序确定最大重叠重叠间隔

时间:2018-11-26 22:22:47

标签: c++

我们应该通过创建一个下限为0到上限为100的数组来做到这一点。 应该看起来像这样:

输入一个整数定界封闭列表,每行一个,为[0,99]的子间隔。

(Enter -1 to stop)
Interval (eg: 7 10): 3 97
Interval (eg: 7 10): 5 55
Interval (eg: 7 10): 60 72
Interval (eg: 7 10): 35 82
Interval (eg: 7 10): -1
The largest number of overlapping intervals is 3.
[35,55]
[60,72]

到目前为止,我有这样的事情

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int list[100] = {0};
int intervalOne; //input and output for the first interval inputted
int intervalTwo; // input and output value for the second interval inputted
int overlap; //  how many of the intervals that were inputted also overlap

//Function Prototype
void initialize(int arr[], int size);
void read(int arr[], int size);
void print(int arr[], int size);


int main ()
{
   cout << "Enter a list of integer delimited closed intervals" << endl;
   cout << "one per line, that are subintervals of [0,99]." << endl;
   cout << " (Enter -1 to stop)" << endl;

   do {
       cout << "Interval (eg: 7 10) :";
       cin >> intervalOne;
       if (intervalOne == -1)
           break;
       cin >> intervalTwo;
       cout << intervalOne << " " << intervalTwo << endl;
   } while (intervalOne != -1);

   cout << "loop has stopped with -1 input" << endl;

   cout << "The largest number of overlapping intervals is " << overlap << endl;
  return 0;
}

我不确定应该如何从这里开始。

0 个答案:

没有答案