Last active
June 26, 2021 18:08
-
-
Save ValeryVerkhoturov/e8afc1623bec8cbaf9534e7d172529c0 to your computer and use it in GitHub Desktop.
Экзаменационное задание Билет 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| namespace Exam | |
| { | |
| abstract class Rodent | |
| { | |
| public string TypeName { get; private set; } | |
| public int NumOfTeeth { get; private set; } | |
| public float? TailLength { get; private set; } | |
| public float? NoseLength { get; private set; } | |
| public Rodent(string typeName, int numOfTeeth, float? tailLength, | |
| float? noseLength) | |
| { | |
| TypeName = typeName; | |
| NumOfTeeth = numOfTeeth; | |
| TailLength = tailLength; | |
| NoseLength = noseLength; | |
| } | |
| } | |
| class RodentChild1 : Rodent | |
| { | |
| public RodentChild1(int numOfTeeth, float tailLength, | |
| float noseLength) : | |
| base("Шикотанская полевка", numOfTeeth, tailLength, noseLength) | |
| { | |
| } | |
| } | |
| class RodentChild2 : Rodent | |
| { | |
| public RodentChild2(int numOfTeeth) : | |
| base("Тушканчик-прыгун", numOfTeeth, null, null) | |
| { | |
| } | |
| } | |
| class RodentChild3 : Rodent | |
| { | |
| public int Age { get; private set; } | |
| public float MustacheLength { get; private set; } | |
| public RodentChild3(int numOfTeeth, float tailLength, float noseLength, | |
| int age, float mustacheLength) : | |
| base("Тувинская полевка", numOfTeeth, tailLength, noseLength) | |
| { | |
| Age = age; | |
| MustacheLength = mustacheLength; | |
| } | |
| } | |
| class Cat | |
| { | |
| public string Name { get; } | |
| public List<Rodent> SpaceForRodents { get; private set; } | |
| public Cat(string name = "Дина") | |
| { | |
| Name = name; | |
| SpaceForRodents = new List<Rodent>(); | |
| } | |
| public bool CanCatch(Rodent rodent) | |
| { | |
| if (rodent.NumOfTeeth <= 5) | |
| return false; | |
| if (rodent.TailLength is not null && rodent.TailLength < 4) | |
| return false; | |
| if (rodent.NoseLength is not null && rodent.NoseLength <= 1) | |
| return false; | |
| return true; | |
| } | |
| public List<Rodent> CatchGroup(List<Rodent> rodents) | |
| { | |
| var remainingRodents = new List<Rodent>(); | |
| var iterations = rodents.Count; | |
| for (int _ = 0; _ < iterations; _++) | |
| { | |
| // favourite rodent | |
| var rodent = rodents.Find(rodent => rodent is RodentChild1); | |
| // any rodent | |
| rodent ??= rodents[0]; | |
| if (!CanCatch(rodent)) | |
| { | |
| remainingRodents.Add(rodent); | |
| rodents.Remove(rodent); | |
| continue; | |
| } | |
| if (rodent is RodentChild1) rodents.Remove(rodent); | |
| else if (rodent is RodentChild2 || rodent is RodentChild3) | |
| { | |
| SpaceForRodents.Add(rodent); | |
| rodents.Remove(rodent); | |
| } | |
| } | |
| return remainingRodents; | |
| } | |
| } | |
| } |
ValeryVerkhoturov
commented
Jun 26, 2021
Author

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment