Sunday, 4 December 2016

job sech

#include<iostream>

using namespace std;

struct job
{
   char c;
   int p;
   int d;
};

int main()
{
int dl;
int n;
int x;

//cout<<"Enter the Deadlne : ";
//cin>>dl;
cout<<"Enter the no. of jobs : ";
cin>>n;
job j[n];

int di[6]={0};

cout<<"Enter the profits in decreasing order : \n";

cout<<"Enter job name : ";
for(int i=1; i<=n; i++)
{
   cin>>j[i].c;
}
cout<<"Enter profit : ";
for(int i=1; i<=n; i++)
{
    cin>>j[i].p;
}
cout<<"Enter Deadline : ";
for(int i=1; i<=n; i++)
{
    cin>>j[i].d;
}

cout<<"You Entered \n";
for(int i=1; i<=n; i++)
{
   cout<<j[i].c<<" ";
   cout<<j[i].p<<" ";
   cout<<j[i].d<<" ";
   cout<<endl;
}

//x=j[1].d;
for(int i=1; i<=n; i++)
{
  x=j[i].d;
  if(di[x] == 0)
  {
   di[x]=j[i].p;
  }
  else
  {
      int t=j[i].d;
      while(di[t]!=0)
      {
          t--;
      }
      if(t>=1)
         di[t]=j[i].p;
  }
}
int sum=0;
for(int i=1; i<=n; i++)
{
    cout<<di[i]<<"  ";
   sum = sum+di[i];
}
cout<<"!!! Total Profit is "<<sum;
}



No comments:

Post a Comment