Skip to content

Commit 9cbc141

Browse files
authored
Update BestTime2Party.c
1 parent 0a4882b commit 9cbc141

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

BestTime2Party.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
#include <stdio.h>
22

3-
void findMaxBands(int n,int arr1[n],int depr[n]);
3+
void findMaxActivities(int n,int arr1[n],int depr[n]);
44
void quickSort(int a[],int l,int h);
55
int partition(int a[],int l,int h);
66

77
int main(){
8-
printf("Doste arithmo pareuriskomenon mpanton: ");
8+
printf("Give number of activities: ");
99
int n;
1010
scanf("%d",&n);
1111
int arrl[n],depr[n];
1212
for(int i = 0; i<n; i++){
13-
printf("%d mpanta\n",i+1);
14-
printf("Doste ora afixis %d mpantas: ",i+1);
13+
printf("%d activity\n",i+1);
14+
printf("Start time of %d activity: ",i+1);
1515
scanf("%d",&arrl[i]);
16-
printf("Doste ora anaxorisis %d mpantas: ",i+1);
16+
printf("Finish time of %d activity: ",i+1);
1717
scanf("%d",&depr[i]);
1818
}
19-
findMaxBands(n,arrl,depr);
19+
findMaxActivities(n,arrl,depr);
2020
return 0;
2121
}
2222

23-
void findMaxBands(int n,int arrl[n],int depr[n]){
24-
quickSort(arrl,0,n-1); //taksinomo tous pinakes asxetos ama xalao tis periodous me grigori methodo
23+
void findMaxActivities(int n,int arrl[n],int depr[n]){
24+
quickSort(arrl,0,n-1); //sort the tables(you can use your own sort method)
2525
quickSort(depr,0,n-1);
2626
int depr_time[n];
27-
int bandsIn = 1,maxBands = 1;
27+
int activitiesIn = 1,maxActivities = 1;
2828
depr_time[0] = depr[0];
2929
int i = 1, j = 0,k = 0;
3030

31-
while (i < n && j < n){ //elengxo mexri na teleiosoun oi pinakes
31+
while (i < n && j < n){
3232
if (arrl[i] < depr[j]){
33-
bandsIn++; //auksano tis mpantes stin idia periodo
34-
if (bandsIn >= maxBands){
35-
if(bandsIn == maxBands)k++; //to k einai gia na kratiso tis perissoteres fores poy emfanizete idios arithmos mpantwn
33+
activitiesIn++;
34+
if (activitiesIn >= maxActivities){
35+
if(activitiesIn == maxActivities)k++; //k is to keep the number of the same activities in 2 or more time periods
3636
else k = 0;
37-
maxBands = bandsIn;
38-
depr_time[k] = depr[j]; //kratao tin anaxorisi tis megistis mpantas
37+
maxActivities = activitiesIn;
38+
depr_time[k] = depr[j]; //departure time of max activity
3939
}
4040
i++;
4141
}
4242
else{
43-
bandsIn--; //bgazo tin teleutea mpanta afou to arrl den ginete na einai megalitero apo to depr se mia periodo
44-
j++; //auksanontas to j oste to depr na ginei megalitero apo to arrl kai na metraei mpantes apo ekei pou emeine kai oxi apo to 0
43+
activitiesIn--;
44+
j++;
4545
}
4646
}
4747
for(i=0; i<=k; i++){
48-
printf("Maximum Number of Bands : %d at time %d-%d\n",maxBands,depr_time[i]-1,depr_time[i]);
48+
printf("Maximum Number of Activities : %d at time period %d-%d\n",maxBands,depr_time[i]-1,depr_time[i]);
4949
}
5050
}
5151

0 commit comments

Comments
 (0)