Advertisement
illeas

Activity selections

Aug 24th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. using namespace std;
  4.  
  5. void sortarray(int a[], int b[], int n){
  6.     for(int i=0; i<n; i++){
  7.         for (int j=i+1; j<n; j++){
  8.            if (b[i] > b[j]){
  9.               int tem = b[j];
  10.               b[j] = b[i];
  11.               b[i] = tem;
  12.  
  13.               int temp = a[j];
  14.               a[j] = a[i];
  15.               a[i] = temp;
  16.            }
  17.         }
  18.     }
  19. }
  20.  
  21. void maxActivities(int s[], int e[], int n){
  22.     int i, j;
  23.     printf ("Max activities: ");
  24.     i = 0;
  25.     printf("%d-%d ", s[i], e[i]);
  26.  
  27.     for (j = 1; j < n; j++){
  28.        if (s[j] >= e[i]){
  29.           printf("%d-%d ", s[j], e[j]);
  30.           i = j;
  31.        }
  32.     }
  33. }
  34.  
  35. int main()
  36. {
  37.     int s[] =  {2, 3, 4, 1, 2};
  38.     int e[] =  {5, 4, 7, 2, 3};
  39.     int n = sizeof(s)/sizeof(s[0]);
  40.     sortarray(s, e, n);
  41.     maxActivities(s, e, n);
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement