Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lab8
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var KPP = new Checkpoint(100, 100); var v1 = new Enrollee("Пётр", false ); KPP.VisitorWantToISIT.Add(v1); var v2 = new Teacher("Сергей Александрович", true); KPP.VisitorWantToISIT.Add(v2); var v3 = new Student("Данил", true); KPP.VisitorWantToISIT.Add(v3); var v4 = new Dog("Барсик", true); KPP.VisitorWantToISIT.Add(v4); var v5 = new Squirrel("Белочка"); KPP.VisitorWantToISIT.Add(v5); var v6 = new Dove("Голубь Наташа"); KPP.VisitorWantToISIT.Add(v6); var v7 = new Enrollee("Надежда", false); KPP.VisitorWantToISIT.Add(v7); var v8 = new Teacher("Анна Анатольевна", true); KPP.VisitorWantToISIT.Add(v8); var v9 = new Student("Моника", true); KPP.VisitorWantToISIT.Add(v9); var v10 = new Dog("Бублик", true); KPP.VisitorWantToISIT.Add(v10); var v11 = new Teacher("Тамара Алексеевна", false); KPP.VisitorWantToISIT.Add(v11); var v12 = new Enrollee("Егор", false); KPP.VisitorWantToISIT.Add(v12); var v13 = new Student("Глеб", false); KPP.VisitorWantToISIT.Add(v13); var v14 = new Enrollee("Максим", false); KPP.VisitorWantToISIT.Add(v14); var v15 = new Teacher("Ирина Фёдоровна", false); KPP.VisitorWantToISIT.Add(v15); Console.WriteLine(KPP.Info()); KPP.Check(); Console.WriteLine(KPP.Info()); } } public class Checkpoint{ public Checkpoint(int masks, int antiseptic){ NumbersOfMasks = masks; AmountOfAntiseptic = antiseptic; } public int NumbersOfMasks; public int AmountOfAntiseptic; public List<IVisitor> VisitorWantToISIT = new List<IVisitor>(); public List<IVisitor> VisitorCanToISIT = new List<IVisitor>(); public void Check(){ foreach(IVisitor v in VisitorWantToISIT){ if(v is ICanPutOnMask && v is ICanDisinfectHand){ if(!((ICanPutOnMask)v).IsHaveMask){NumbersOfMasks--;} AmountOfAntiseptic--; VisitorCanToISIT.Add(v); //VisitorWantToISIT.Remove(v); } } foreach(IVisitor v in VisitorCanToISIT){ VisitorWantToISIT.Remove(v); } } public string Info(){ string result = "Кол-во антисептика: " + AmountOfAntiseptic + "\nКол-во масок: " + NumbersOfMasks + "\n\nЖелающие пройти: " + VisitorWantToISIT.Count + "\nМогут пройти: " + VisitorCanToISIT.Count ; return result + "\n\n"; } } public interface IVisitor{} public interface ICanDisinfectHand{} public interface ICanPutOnMask{ bool IsHaveMask{ get; set; } } public abstract class Human{ public string Name; } public class Enrollee:Human, ICanDisinfectHand, ICanPutOnMask, IVisitor{ public Enrollee(string name, bool mask){ Name = name; mask = this.mask; } public bool IsHaveMask{get {return mask;} set{mask = value;}} private bool mask; } public class Teacher:Human, ICanDisinfectHand, ICanPutOnMask, IVisitor{ public Teacher(string name, bool mask){ Name = name; IsHaveMask = mask; } public bool IsHaveMask{get {return mask;} set{mask = value;}} private bool mask; } public class Student:Human, ICanDisinfectHand, ICanPutOnMask, IVisitor{ public Student(string name, bool mask){ Name = name; IsHaveMask = mask; } public bool IsHaveMask{get {return mask;} set{mask = value;}} private bool mask; } public abstract class Animal{ public string Name; } public class Dog:Animal, ICanPutOnMask, IVisitor{ public Dog(string name, bool mask){ Name = name; IsHaveMask = mask; } public bool IsHaveMask{get {return mask;} set{mask = value;}} private bool mask; } public class Dove:Animal, IVisitor{ public Dove(string name){ Name = name; } } public class Squirrel:Animal, IVisitor{ public Squirrel(string name){ Name = name; } } }
run
|
edit
|
history
|
help
0
Matrix Main Diagonal
Hallo world
Volatile madness
346625
nthFromLastElement
ds
default branch name
Hex character codes
ss
Insertion Sort