You are on page 1of 2

#include<stdio.

h>
struct hosp
{
int maxstud;
int pref[20];
int seatsfilled;
int alloc[20];
};
struct hosp h[20];

struct stud
{
int pref[20];
int alloc;
};
struct stud s[25];
int m,n,totalseats=0;

void allocate()
{
int freecnt=totalseats;
while (freecnt > 0)
{
// Pick the first free man (we could pick any)
int i=0,j=0,k=0,l=0,p,q=0,freehosseat;
while(h[i].seatsfilled<h[i].maxstud)
{
if(h[i].pref[j]==s[k].pref[q])
if(s[k].alloc==-1)
{
s[k].alloc = i;
h[i].alloc[l++]=k;
h[i].seatsfilled++;

j++;
k++;
q++;
freecnt--;
}
else
{
for(p=0;s[k].pref[q]!='\0';p++)
if(s[k].alloc!=-1 && s[k].pref[p]==i)
{
freehosseat=s[k].alloc;
s[k].alloc=i;
h[i].alloc[l++]=k;
h[i].seatsfilled++;
}
}
i++;
j++;

} // End of the for loop that goes to all women in m's list
} // End of main while loop
}
int main()
{

int i,j,totalseats;

printf("Enter number of hospitals:");


scanf("%d",&m);

printf("Enter the number of seats and preference of hospital:\n");


for(i=0;i<m;i++)
{
h[i].seatsfilled=0;
printf("Enter the number of seats:");
scanf("%d",&h[i].maxstud);
totalseats+=h[i].maxstud;
printf("Enter the preference:");
for(j=0;j<h[i].maxstud;j++)
scanf("%d",&h[i].pref);
}
printf("Total number of seats available in %d hospital=%d\n",m,totalseats);
printf("Enter number of students:");
scanf("%d",&n);
printf("Enter the preference of students:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&s[i].pref[j]);
if(s[i].pref[j]==-1)
break;
}
s[i].alloc=-1;
}

You might also like