Source Code:
#include<iostream.h>
#include<conio.h>
void job(int*,int*,int,int);
void main()
{clrscr();
cout<<"Program created by Tarun Rawat Job Scheduling\n\n";
int profit[20],dead[20],n,i,j,maxdead;
cout<<"Enter number of element : ";
cin>>n;
cout<<"Enter profit in descending order: \n";
for(i=0;i<n;i++)
{cin>>profit[i];
}
cout<<"Enter deadline according to profit value typed above : \n";
for(i=0;i<n;i++)
{cin>>dead[i];
}
cout<<"Enter maximum deadline : ";
cin>>maxdead;
job(profit,dead,n,maxdead);
getch();
}
void job(int profit[],int dead[],int n,int maxdead)
{ int result[20],total=0,x=0;
for(int i=0;i<maxdead;i++)
{result[i]=0;
}
for( i=0;i<n;i++)
{ if(result[dead[i]-1]==0)
{result[dead[i]-1]=profit[i];
total=total+profit[i];
}
else
{ for(int j=dead[i]-1;j>=0;j--)
{if(result[j]==0)
{result[j]=profit[i];
total=total+profit[i];
}
}
}
}
cout<<"Total profit is " <<total;
cout<<"\nOutput array is : \n";
for(i=0;i<maxdead;i++)
{cout<<"At index "<<i+1<<" "<<result[i]<<"\n"; ///Tarun rawat
}
}
Welcome to " way2cplusplus.blogspot.in " Objective of this blog is to implement various Computer Science Engineering Lab problems into C++ programming language. These are basically most common Lab Exercise problems based on the curriculum of engineering colleges throughout the Nation. These lab exercises are also relevant to Data structure. Simply C++ programming zone...
No comments:
Post a Comment