Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
899 B
2
Indexable
Never
#include<stdio.h>
#include<stdlib.h>

struct work{
    char task;
    int start_time;
    int end_time;
};
struct work input[50];


void printMaxActivities(int s[], int f[], int n, struct work arr[])
{
    int i, j;
    printf ("Following activities are selected:\n");
    i = 0;
    printf("%d ", i);

    for (j = 1; j < n; j++)
    {
      if (s[j] >= f[i])
      {
          printf ("%c\n", arr[j].task);
          i = j;
      }
    }
}

int main()
{
    int num, s[50], f[50];
    scanf("%d", &num);

    for(int i=0; i<num; i++)
    {
        scanf("%c", &input[i].task);
        scanf("%d%d", &input[i].start_time, &input[i].end_time);
    }
    int break_time;
    scanf("%d", &break_time);

    for(int i=0; i<num; i++)
    {
        s[i]=input[i].start_time;
        f[i]=input[i].end_time;
    }

    printMaxActivities(s,f,num,input);
}