using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
List<Fish> fishes = new List<Fish>()
{
new Fish(1, FishType.A),
new Fish(1, FishType.B),
new Fish(1, FishType.A)
};
Fish mainFish = new Fish(2, FishType.A);
mainFish.Eat(fishes);
Console.WriteLine(mainFish);
}
}
class Fish
{
public int Length { get; private set; }
public FishType Type { get; private set; }
public Fish(int length, FishType type)
{
Length = length;
Type = type;
}
public void Eat(List<Fish> fishes)
{
if (Type == FishType.B)
return;
foreach (Fish fish in fishes)
{
if (fish.Type == FishType.A && fish.Length < Length
|| fish.Type == FishType.B)
{
Length += fish.Length;
fishes.Remove(fish);
break;
}
}
}
public override string ToString()
{
return $"Length: {Length}, Type; {Type.ToString()}";
}
}
public enum FishType
{
A,
B
}
}