/*
Veidoja : Roberts Dorbe
Grupa : 110
Praktiskais darbs 6.3
Imantotais compiler : onlinegdb
*/
using System;
using System.Collections.Generic;

class Program
{
static int[][] vietas = new int[][]
{
new int[] {0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0},
new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] {0,0,0,0,0,0,1,0,0,0,0,0,0},
new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] {0,0,0,0,0,1,0,0,0,0,0,0,0}
};
static List<string> rezervacijas = new List<string>();
static void Main()
{
ApstradatIzveli();
}
static void ParaditZali(int[][] vietas)
{
Console.WriteLine("\n Kinozale ");
Console.WriteLine("[O] - briva, [X] - aiznemta\n");
for (int r = 0; r < vietas.Length; r++)
{
int rindaNr = vietas.Length - r;
Console.Write($"{rindaNr,2}: ");
for (int s = 0; s < vietas[r].Length; s++)
{
if (vietas[r][s] == 0)
Console.Write("[O] ");
else
Console.Write("[X] ");
}
Console.WriteLine();
}}
static bool RezervetVietu(int[][] vietas, List<string> rezervacijas)
{
Console.Write("Ievadiet rindas numuru (1-9): ");
if (!int.TryParse(Console.ReadLine(), out int row))
{
Console.WriteLine("Nederigs rindas numurs.");
return false;
}
Console.Write("Ievadiet vietas numuru: ");
if (!int.TryParse(Console.ReadLine(), out int seat))
{
Console.WriteLine("Nederigs vietas numurs.");
return false;
}
int rowIndex = vietas.Length - row;
int seatIndex = seat - 1;
if (rowIndex < 0 || rowIndex >= vietas.Length)
{
Console.WriteLine("Tada rinda neeksiste.");
return false;
}
if (seatIndex < 0 || seatIndex >= vietas[rowIndex].Length)
{
Console.WriteLine("ši rinda neeksiste.");
return false;
}
if (vietas[rowIndex][seatIndex] == 1)
{
Console.WriteLine("Ši vieta jau ir aiznemta.");
return false;
}
vietas[rowIndex][seatIndex] = 1;

string rez = $"Rinda {row}, Vieta {seat}";
rezervacijas.Add(rez);
Console.WriteLine("Rezervacija veiksmiga: " + rez);
return true;
}
static void ApstradatIzveli()
{
bool exit = false;
while (!exit)
{
Console.WriteLine("1 - Paradit zali");
Console.WriteLine("2 - Rezervet vietu");
Console.WriteLine("3 - Rezervaciju saraksts");
Console.WriteLine("4 - Iziet");
Console.Write("Izvele: ");
string choice = Console.ReadLine();
Console.WriteLine();
switch (choice)
{
case "1":
ParaditZali(vietas);
break;
case "2":
RezervetVietu(vietas, rezervacijas);
break;
case "3":
if (rezervacijas.Count == 0)
{
Console.WriteLine("Nav nevienas rezervacijas.\n");
}
else
{
Console.WriteLine("Rezervacijas:");
foreach (var r in rezervacijas)
Console.WriteLine("- " + r);
Console.WriteLine();
}
break;
case "4":
exit = true;
break;
default:
Console.WriteLine("Nederiga izvele.\n");
break;
}
}
}
}