|
1 | 1 | #include <stdio.h> |
2 | 2 |
|
3 | | -void findMaxBands(int n,int arr1[n],int depr[n]); |
| 3 | +void findMaxActivities(int n,int arr1[n],int depr[n]); |
4 | 4 | void quickSort(int a[],int l,int h); |
5 | 5 | int partition(int a[],int l,int h); |
6 | 6 |
|
7 | 7 | int main(){ |
8 | | - printf("Doste arithmo pareuriskomenon mpanton: "); |
| 8 | + printf("Give number of activities: "); |
9 | 9 | int n; |
10 | 10 | scanf("%d",&n); |
11 | 11 | int arrl[n],depr[n]; |
12 | 12 | 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); |
15 | 15 | scanf("%d",&arrl[i]); |
16 | | - printf("Doste ora anaxorisis %d mpantas: ",i+1); |
| 16 | + printf("Finish time of %d activity: ",i+1); |
17 | 17 | scanf("%d",&depr[i]); |
18 | 18 | } |
19 | | - findMaxBands(n,arrl,depr); |
| 19 | + findMaxActivities(n,arrl,depr); |
20 | 20 | return 0; |
21 | 21 | } |
22 | 22 |
|
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) |
25 | 25 | quickSort(depr,0,n-1); |
26 | 26 | int depr_time[n]; |
27 | | - int bandsIn = 1,maxBands = 1; |
| 27 | + int activitiesIn = 1,maxActivities = 1; |
28 | 28 | depr_time[0] = depr[0]; |
29 | 29 | int i = 1, j = 0,k = 0; |
30 | 30 |
|
31 | | - while (i < n && j < n){ //elengxo mexri na teleiosoun oi pinakes |
| 31 | + while (i < n && j < n){ |
32 | 32 | 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 |
36 | 36 | 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 |
39 | 39 | } |
40 | 40 | i++; |
41 | 41 | } |
42 | 42 | 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++; |
45 | 45 | } |
46 | 46 | } |
47 | 47 | 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]); |
49 | 49 | } |
50 | 50 | } |
51 | 51 |
|
|
0 commit comments