-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry_activity.cpp
More file actions
60 lines (54 loc) · 994 Bytes
/
Copy pathtry_activity.cpp
File metadata and controls
60 lines (54 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Activity Selection Problem */
#include <iostream>
#include <algorithm>
using namespace std;
typedef struct activity{
int st;
int ft;
int id;
}activity;
bool compare(activity a, activity b)
{
return a.ft < b.ft;
}
void selection(activity arr[], int n)
{
int t;
t = arr[0].ft;
cout<<"Activities: "<<arr[0].id<<" ";
for (int i=0; i<n; i++){
if (arr[i].st>=t){
cout<<arr[i].id<<" ";
t = arr[i].ft;
}
}
}
int main(){
int n;
cout<<"Enter the number of activities: ";
cin>>n;
activity arr[n];
cout<<"Enter the activity id, start time, finish time (id st fd)"<<endl;
for (int i=0; i<n; i++){
cin>>arr[i].id;
cin>>arr[i].st;
cin>>arr[i].ft;
}
sort(arr, arr+n, compare);
selection(arr, n);
return 0;
}
/*
Enter the number of activities: 8
Enter the activity id, start time, finish time (id st fd)
1 1 3
2 0 4
3 1 2
4 4 6
5 2 9
6 5 8
7 3 5
8 4 5
Activities: 3 7 6
--------------------------------
*/