added another Doboz implementation
This commit is contained in:
84
fordulo_3/Doboz/DobozFeladat/Program.cs
Normal file
84
fordulo_3/Doboz/DobozFeladat/Program.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace DobozFeladat
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static List<Box> Boxes = new List<Box>();
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string path = $@"../../../../../fordulo_3/forrasok/dobozok.txt";
|
||||
char[] AllBoxes = File.ReadAllText(path).ToCharArray();
|
||||
//char[] AllBoxes = { 'A','B','A','C', 'A','C','B','C','C','A'};
|
||||
|
||||
int ACount = 0;
|
||||
int BCount = 0;
|
||||
int MaximumLength = 0;
|
||||
int TotalBoxPlaceUsed = 0;
|
||||
|
||||
foreach (char character in AllBoxes)
|
||||
{
|
||||
bool IsDefected = false;
|
||||
|
||||
if (character == 'A')
|
||||
{
|
||||
ACount++;
|
||||
if (ACount % 25 == 0)
|
||||
{
|
||||
// switch to true for c || false for b
|
||||
IsDefected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (character == 'B')
|
||||
{
|
||||
BCount++;
|
||||
if (BCount % 25 == 0)
|
||||
{
|
||||
// switch to true for c || false for b
|
||||
IsDefected = true;
|
||||
}
|
||||
}
|
||||
|
||||
Box box = new Box(character, IsDefected);
|
||||
|
||||
|
||||
foreach (Box Place in Boxes)
|
||||
{
|
||||
|
||||
if (Place.AddedChild(box))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Boxes.Count > MaximumLength)
|
||||
{
|
||||
MaximumLength = Boxes.Count;
|
||||
}
|
||||
|
||||
if (box.Parent == null)
|
||||
{
|
||||
Boxes.Add(box);
|
||||
TotalBoxPlaceUsed++;
|
||||
}
|
||||
|
||||
Boxes.RemoveAll(x => x.ReadyForPackaging());
|
||||
}
|
||||
|
||||
int length = 0;
|
||||
foreach (var Box in Boxes)
|
||||
{
|
||||
length += Box.PrintBoxRecursively().Count();
|
||||
}
|
||||
Console.WriteLine($"Maximum length needed: {length}");
|
||||
Console.WriteLine($"Total box place needed: {TotalBoxPlaceUsed}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user