#include
#include
void main()
{
int n,i,j,k,a,b,c,max,r,q,tp=0;
int p[20],d[20],tem[20],in[20],job[20];
clrscr();
freopen("c:\\work\\input4.txt","r",stdin);
printf("\nEnter number of profit:");
scanf("%d",&n);
printf("Enter profit & date line");
for(i=1;i<=n;i++)
{
printf("\nProfit: ");
scanf("%d",&p[i]);
printf("\nDate line: ");
scanf("%d",&d[i]);
tem[i]=p[i];
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
if(p[i]
{
max=p[i];
p[i]=p[j];
p[j]=max;
}
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(p[i]==tem[j])
in[i]=j;
}
printf("\n\nIndex:");
for(i=1;i<=n;i++)
printf("%d ",in[i]);
job[0]=0;
d[0]=0;
in[0]=0;
job[1]=1;
k=1;
for(i=2;i<=n;i++)
{
r=k;
while(d[in[job[r]]]>d[in[i]]&&d[in[job[r]]]!=r)
r=r-1;
if(d[in[job[r]]]<=d[in[i]]&&d[in[i]]>r)
{
for(q=k;q>=r+1;q--)
job[q+1]=job[q];
job[r+1]=i;
k=k+1;
}
}
for(i=1;i<=r;i++)
tp=tp+p[job[i]];
printf("\n\nTotal Profit=%d",tp);
printf("\n\nThe job Sequence is:\n\n");
for(i=1;i<=r;i++)
printf(" %d ",in[job[i]]);
printf("\n\n Job array:");
for(i=1;i<=r;i++)
printf(" %d ",job[i]);
// getch();
}
0 comments:
Post a Comment