using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static string[, ,] Seat = new string[100, 100, 100];
static string[, ,] initialSeat = new string[100,100,100];
static string[, ,] initialsub = new string[100,100,100];
static string[] subjectcode = { "11cs101", "11ee203", "11ec309"};
static string[,] rollnosub = {
{"12bcs059","12bcs060","12bcs061","12bcs062","12bcs063","12bcs064","12bcs065","12bcs066",
"12bcs067","12bcs068","null","null"},
{"12bee059","12bee060","12bee061","12bee062","12bee063","12bee064","12bee065","12bee066",
"12bee067","12bee068","null","null"},
{"12bec059","null","null","null","null","null","null","null","null","null","null","null"}
};
}
catch (Exception e)
{
}
}
static void initializeseats()
{
try
{
capacityChecking();
for (limit = 0; limit < grouplimit; limit++)
{
groups[limit] = limit;
}
for (limit = 0; limit < noofgroups; limit++)
{
rolllimit[limit] = 0;
}
limit = 0;
for (int hall = 0; hall < hallname.Length; hall++)
{
breakvalue = 0;
TempCapacity[hall] = 1;
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; )
{
int assign = 1;
if (rollnosub[groups[limit], rolllimit[groups[limit]]] !=
"null")
{
initialSeat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] = subjectcode[groups[limit]];
col++;
}
else
{
assign = 0;
}
if (++rolllimit[groups[limit]] != 12)
{
limit++;
}
else
{
groups[limit] = cgrouplimit++;
limit++;
}
if (limit == grouplimit)
{
limit = 0;
}
if (assign==0)
{
continue;
}
if (TempCapacity[hall] < Capacity[hall])
{
TempCapacity[hall]++;
}
else
{
breakvalue = 1;
break;
}
}
if (breakvalue == 1)
{
break;
}
}
}
}
catch (Exception e)
{
// Console.WriteLine(e);
}
}
static bool isgraphcoloring()
{
for (int hall = 0; hall < hallname.Length; hall++)
{
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; col++)
{
if ((row != 0) && (col != 0))
{
if (initialsub[hall, row, col] == initialsub[hall, row - 1,
col] || initialsub[hall, row, col] == initialsub[hall, row, col - 1])
{
return false;
}
}
else if (row == 0 && col == 0)
{
}
else if (col == 0)
{
if (initialsub[hall, row, col] == initialsub[hall, row - 1,
col])
{
return false;
}
}
else if (row == 0)
{
if (initialsub[hall, row, col] == initialsub[hall, row, col -
1])
{
return false;
}
}
else
{
}
}
}
}
return true;
}
static void graphcolor()
{
cgrouplimit = grouplimit;
for (limit = 0; limit < grouplimit; limit++)
{
groups[limit] = limit;
}
for (limit = 0; limit < noofgroups; limit++)
{
rolllimit[limit] = 0;
}
limit = 0;
for (int hall = 0; hall < hallname.Length; hall++)
{
try
{
breakvalue = 0;
TempCapacity[hall] = 1;
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; )
{
int assign = 1;
if (rollnosub[groups[limit], rolllimit[groups[limit]]] !=
"null")
{
if (row == 0)
{
Seat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
}
else if (col!= 0)
{
if((subjectcode[groups[limit]] == initialsub[hall,
row - 1, col] && subjectcode[groups[limit]] == initialsub[hall, row, col - 1] ))
{
limit++;
if (limit == grouplimit)
{
limit = 0;
}
Seat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
if (rollnosub[groups[limit],
rolllimit[groups[limit]]] == "null")
{
assign = 0;
}
}
else
{
Seat[hall, row, col] =
rollnosub[groups[limit], rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
}
}
else if (col == 0)
{
if ((subjectcode[groups[limit]] ==
initialsub[hall, row - 1, col] ))
{
limit++;
if (limit == grouplimit)
{
limit = 0;
}
if (++(rolllimit[groups[limit]]) != 12)
{
limit++;
}
else
{
groups[limit] = cgrouplimit++;
limit++;
}
if (limit == grouplimit)
{
limit = 0;
}
if (assign == 0)
{
continue;
}
if (TempCapacity[hall] < Capacity[hall])
{
TempCapacity[hall]++;
}
else
{
breakvalue = 1;
break;
}
}
if (breakvalue == 1)
{
break;
}
}
}
catch (Exception e)
{
//Console.WriteLine(hallname[hall] + e);
}
}
Console.WriteLine("**************SEATING ARRANGEMENTS**************");
for (int hall = 0; hall < hallname.Length; hall++)
{
Console.WriteLine("HALL NUMBER = " + hallname[hall]);
int seatno = 1;
for (int row = 0; row < Row[hall]; row++)
{
for (int seatnum = 0; seatnum < Column[hall]; seatnum++)
{
Console.Write("\t " + seatno++ + " ");
}
Console.WriteLine();
for (int col = 0; col < Column[hall]; col++)
{
Console.Write("\t" + Seat[hall, row, col] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadLine();
}
static void Main(string[] args)
{
try
{
initializeseats();
if (isgraphcoloring())
{
Console.WriteLine("**************SEATING
ARRANGEMENTS**************");
for (int hall = 0; hall < hallname.Length; hall++)
{
Console.WriteLine("HALL NUMBER = " + hallname[hall]);
int seatno = 1;
for (int row = 0; row < Row[hall]; row++)
{
for (int seatnum = 0; seatnum < Column[hall]; seatnum++)
{
Console.Write("\t " + seatno++ + " ");
}
Console.WriteLine();
for (int col = 0; col < Column[hall]; col++)
{
Console.Write("\t" + initialSeat[hall, row, col] + "
");
}
Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadLine();
}
else
{
graphcolor();
}
}
catch(Exception e)
{
}
}
}
}