📄 babr.bak
字号:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int n,Bu[20],B[20],lc;
int cid[10];
int A[10],Wt[10],chair;
void getdata();
void fcfs();
void sort();
void sort()
{
int temp1,temp2,temp3;
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(A[i]<A[j])
{
temp1=A[i];
A[i]=A[j];
A[j]=temp1;
temp2=cid[i];
cid[i]=cid[j];
cid[j]=temp2;
temp3=B[i];
B[i]=B[j];
B[j]=temp3;
}
}
}
}
void getdata()
{
int i;
printf("\n Enter the no of customers : ");
scanf("%d",&n);
printf("\n Enter the number of chairs : ");
scanf("%d",&chair);
printf("\n INITIALLY BARBER IS SLEEPING ");
lc=n;
if(n>chair)
{
lc=n-chair;
printf("\n %d customers leave out ",lc);
}
for(i=1;i<=lc;i++)
{
printf("\n Enter the arrival time for customer %d =",i);
scanf("%d",&A[i]);
cid[i]=i;
printf("\n Enter The cutting time for customer %d =",i);
scanf("%d",&Bu[i]);
}
}
//First come First served Algorithm
void fcfs()
{
int i,temp;
for(i=1;i<=lc;i++)
{
B[i]=Bu[i];
printf("\n Cutting time for customer %d = %d",i,B[i]);
}
sort();
for(i=1;i<=lc;i++)
printf("\n%d %d %d",cid[i],A[i],B[i]);
Wt[1]=0;
for(i=2;i<=lc;i++)
{ cout<<"\n\n"<<A[i-1]<<"\t"<<B[i-1]<<"\t"<<A[i];
if((B[i-1]+Wt[i-1]+A[i-1])<A[i])
printf("\n The barber is sleeping from %d to %d",(B[i-1]-Wt[i-1]+1+A[i-1]),A[i]);
temp=A[i-1]+B[i-1]+Wt[i-1]-A[i];
if(temp>0)
Wt[i]=temp;
else
Wt[i]=0;
}
for(i=1;i<=lc;i++)
{
printf("\n Waiting time for customer %d = %d",cid[i],Wt[i]);
}
}
void main()
{
clrscr();
getdata();
fcfs();
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -