Skip to content

Instantly share code, notes, and snippets.

@hsuan1117
Created December 9, 2023 15:31
Show Gist options
  • Save hsuan1117/025fc62caabfd5e43e680eeb41578cd1 to your computer and use it in GitHub Desktop.
Save hsuan1117/025fc62caabfd5e43e680eeb41578cd1 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include"function.h"
Table* createTable() {
Table* t = malloc(sizeof(Table));
int s;
scanf(" %d", &s);
t->tableSize = s;
return t;
}
Guest* createGuest() {
Guest *g = (Guest*)malloc(sizeof(Guest));
char* name = malloc(sizeof(char) * 15);
int G,A,D;
scanf(" %s %d %d %d", name, &G, &A, &D);
g->guestName = name;
g->groupSize = G;
g->arriveTime = A;
g->diningTime = D;
return g;
}
Guest* checkLeave(Table **table, int tableCount, int currentTime) {
for(int i=0;i<tableCount;i++){
Table* t = table[i];
if(currentTime == t->leaveTime) {
Guest* gg = t->guest;
if(t->guest == NULL) continue;
t->guest = NULL;
return gg;
}
}
return NULL;
}
int assignTable(Table **table, int tableCount, int currentTime, Guest *guest) {
for(int i=0;i<tableCount;i++) {
Table* t = table[i];
if(t->guest == NULL && t->tableSize >= guest->groupSize) {
t->leaveTime = currentTime + guest->diningTime;
t->guest = guest;
return 1;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment