-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.cpp
More file actions
221 lines (214 loc) · 6.74 KB
/
code.cpp
File metadata and controls
221 lines (214 loc) · 6.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include<stdio.h>
#include<iostream>
#include<vector>
#include<windows.h>
#include<conio.h>
using namespace std;
int V;
void printSolution(int color[]);
void thank_you();
bool isSafe (int v, bool **graph, int color[], int c,int chairs[])
{
for (int i = 0; i < V; i++)
if((graph[v][i] && (c == color[i])) || chairs[c-1]<=0)
return false;
return true;
}
bool graphColoringUtil(bool **graph, int m, int color[], int v,int chairs[])
{
if (v == V)
return true;
for (int c = 1; c <= m; c++)
{
if (isSafe(v, graph, color, c,chairs))
{
color[v] = c;
chairs[c-1]--;
if (graphColoringUtil (graph, m, color, v+1,chairs) == true)
{
return true;
}
color[v] = 0;
}
}
return false;
}
bool graphColoring(bool **graph, int m,int chairs[])
{
int *color = new int[V];
for (int i = 0; i < V; i++)
color[i] = 0;
if (graphColoringUtil(graph, m, color, 0,chairs) == false)
{
cout<<"Sorry we could not find a solution with given number of tables and chairs";
return false;
}
printSolution(color);
return true;
}
void printSolution(int color[])
{ char c;
system("cls");
system("color 0E");
cout<<"Following are the assigned tables for your guests: \n";
for (int i = 0; i < V; i++)
cout<<"Guest "<<i+1<<" is assigned to the table:"<<color[i]<<"\n";
printf("\n");
int maximum=0;
for(int i=0;i<V;i++)
{
if(maximum<color[i])
maximum=color[i];
}
cout<<"Number of tables used for the seating arrangement :"<<maximum;
cout<<"\nPress any key to continue :";
getch();
thank_you();
}
void thank_you()
{
int c=0;
system("cls");
while(c<10){
Sleep(100);
cout<<"\n";
cout<<"\n\n\n\n\n\n\n\n\n\n";
system("color 0E");
cout<<"\t\t\t %%%%%% %% %% %%% %%%% %% %% %% %% %% %%%%%% %% %%\n";Sleep(2100);
system("color 0B");
cout<<"\t\t\t %% %% %% %% %% %% %% %% %% %% %% %% %% %% %% %%\n";Sleep(2100);
system("color 0C");
cout<<"\t\t\t %% %%%%%% %% %% %% %% %% %%% %% %% %% %% %%\n";Sleep(2100);
system("color 0F");
cout<<"\t\t\t %% %% %% %%%%%%% %% %% %% %% %% %% %% %% %% %%\n";Sleep(2100);
system("color 0D");
cout<<"\t\t\t %% %% %% %% %% %% %%%% %% %% %% %%%%%% %%%%%%\n";Sleep(2100);
system("cls");
c++;
}
}
void welcome()
{ cout<<"\n\n\n\n\n\n\n";
system("color 0E");
cout<<"\t %% %% %%%%%% %%%% %%%% %%%%%% %% %% %%%%% %%%% %% %%% %% %% %% %% %%%%% %%%%% \n";Sleep(2100);system("color 0A");
cout<<"\t %% %% %% %% %% %% %% %% %%% %% %% %% % %% %% %% %%% %% %%% %% %% %% %% \n";Sleep(2100);system("color 0D");
cout<<"\t %% % %% %%%%% %% %% %% %% %% %% % %% %% %% %%%% %% %% %% %% % %% %% % %% %%%% %%%% \n";Sleep(2100);system("color 0F");
cout<<"\t %%% %%% %% %% %% %% %% %% %% %%% %% % %% %% %%%%%%%% %% %%% %% %%% %% %% %% \n";Sleep(2100);system("color 0C");
cout<<"\t %% %%% %%%%%% %%%% %%%% %%%%%% %% %% %%%%% %% %%%%% %% %% %% %% %% %% %%%%% %% %% \n";Sleep(2100);system("color 0B");
cout<<"\n\n\t\t\t\t\tTHE WEDDING SEATING PLANNER\n";Sleep(3000);
cout<<"\n";
}
bool** takeEdgeInput(int v)
{ system("cls");
system("color 0B");
int i=0,j=0;
bool **edge = (bool **)malloc(v * sizeof(bool *));
printf("Enter 1 if the present guest and the corresponding guest don't prefer to sit together.\n");
printf("Enter 0 if present guest has no problem sitting on the same table as corresponding guest.\n");
for(i=0;i<v;i++)
{
edge[i] = (bool *)malloc(v * sizeof(bool));
printf("For Guest %d \n",i+1);
for(j=0;j<v;j++)
{ if(i==j)
edge[i][j]=0;
else
{printf("Enter 1 or 0 for guest %d :: ",j+1);
cin>>edge[i][j];
}
}
cout<<"\n";
}
int reenter;
for(i=0;i<v;i++)
{
for(j=0;j<v;j++)
{
if(edge[i][j]!=edge[j][i])
{ if(edge[i][j]==1)
{
printf("The guest %d does not prefer to sit with guest %d \n",i+1,j+1);
printf("Please re enter if guest %d prefers to sit with guest %d (0) or not (1):",i+1,j+1);
cin>>reenter;
}
else
{
printf("The guest %d does not prefer to sit with guest %d \n",j+1,i+1);
printf("Please re enter if guest %d prefers to sit with guest %d (0) or not (1):",j+1,i+1);
cin>>reenter;
}
edge[i][j]=reenter;
edge[j][i]=reenter;
}
}
}
return edge;
}
int main()
{
int v,m,choice;
welcome();
system("cls");
system("color 0D");
cout<<"1.Plan new wedding seating arrangements:\n";
cout<<"2.Exit\n";
cout<<"3.Enter your choice:";
cin>>choice;
system("cls");
system("color 0A");
if(choice==1)
{ int m,chair,i,j;
bool temp;
cout<<"Enter the no of guests in your wedding:\n";
cin>>V;
if(V<=0)
{
cout<<"\nYou cannot have zero and less guests in your wedding!! Please re-enter the choice::";
int z;
cin>>z;
while(z<=0)
{
cout<<"\nYou cannot have zero and less guests in your wedding!! Please re-enter the choice::";
cin>>z;
}
V=z;
}
cout<<"Enter the maximum number of tables for your wedding:\n";
cin>>m;
if(m<=0)
{
cout<<"\nYou cannot have zero and less tables in your wedding!! Please re-enter the choice::";
int z;
cin>>z;
while(z<=0)
{
cout<<"\nYou cannot have zero and less tables in your wedding!! Please re-enter the choice::";
cin>>z;
}
m=z;
}
cout<<"Enter the no of chairs per table:\n";
cin>>chair;
if(chair<=0)
{
cout<<"\nYou cannot have zero and less tables in your wedding!! Please re-enter the choice::";
int z;
cin>>z;
while(z<=0)
{
cout<<"\nYou cannot have zero and less tables in your wedding!! Please re-enter the choice::";
cin>>z;
}
chair=z;
}
int chairs[1000];
for(int i=0;i<m;i++)
{
chairs[i]=chair;
}
cout<<"\n";
bool **graph = takeEdgeInput(V);
graphColoring(graph,m,chairs);
}
return 0;
}