-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab 6_Prog 4.cpp
68 lines (68 loc) · 1.34 KB
/
Lab 6_Prog 4.cpp
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
61
62
63
64
65
66
67
68
//Q6.4
#include<bits/stdc++.h>
using namespace std;
struct activity{
char name;
int st;
int ed;
};
bool compare_two_activities_1(activity a,activity b){
if(a.st!=b.st){
return a.st<b.st;
}
else{
return a.ed<b.ed;
}
}
bool compare_two_activities_2(activity a,activity b){
if(a.ed!=b.ed){
return a.ed<b.ed;
}
else{
return a.st<b.st;
}
}
int main(){
int n,take=0;
cout<<"Enter the number of Activities"<<endl;
cin>>n;
cout<<"Enter activity details"<<endl;
struct activity ac[n];
for(int i=0;i<n;i++){
cin>>ac[i].name>>ac[i].st>>ac[i].ed;
}
sort(ac,ac+n,compare_two_activities_1);
char ac_of_choice;
cout<<"Enter the activity of your choice"<<endl;
cin>>ac_of_choice;
int i=0;
for(i=0;i<n;i++){
if(ac[i].name==ac_of_choice){
break;
}
}
int id=i;
int ed=ac[id].ed;
for(int i=id+1;i<n;i++){
if(ac[i].st>=ed){
take++;
ed=ac[i].ed;
}
}
sort(ac,ac+n,compare_two_activities_2);
i=0;
for(i=0;i<n;i++){
if(ac[i].name==ac_of_choice){
break;
}
}
id=i;
int st=ac[id].st;
for(int id=i-1;i>=0;i--){
if(ac[i].ed<=st){
take++;
st=ac[i].st;
}
}
cout<<take+1<<endl;
}