Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
970 B
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

struct Item
{
    string activity;
    double start, end;
};

bool comp(Item i1, Item i2)
{
    return (i1.end < i2.end);
}

int main()
{
    int n;
    cout << "enter the number of items: ";
    cin >> n;
    Item item[n];
    for (int i = 0; i < n; i++)
    {
        cout << "activity name:";
        cin >> item[i].activity;
        cout << "start time:";
        cin >> item[i].start;
        cout << "end time:";
        cin >> item[i].end;
    }
    sort(item, item + n, comp);
    for (int i = 0; i < n; i++)
    {
        cout << "activity name:" << item[i].activity << "     start time:" << item[i].start << "     end time:" << item[i].end << endl;
    }
    int count = 1, j = 0;
    for (int i = 1; i < n; i++)
    {
        if (item[j].end <= item[i].start)
        {
            count++;
            j = i;
        }
    }
    cout << '\n'<< count;
    return 0;
}