コード例 #1
0
ファイル: Program.cs プロジェクト: IskraK/SoftUni-Homework
        static void Main(string[] args)
        {
            List <IBuyer> citizensAndRebels = new List <IBuyer>();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] info = Console.ReadLine().Split();

                if (info.Length == 3)
                {
                    string name  = info[0];
                    int    age   = int.Parse(info[1]);
                    string group = info[2];

                    Rebel rebel = new Rebel(name, age, group);

                    citizensAndRebels.Add(rebel);
                }
                else if (info.Length == 4)
                {
                    string name      = info[0];
                    int    age       = int.Parse(info[1]);
                    string id        = info[2];
                    string birthdate = info[3];

                    Citizen citizen = new Citizen(name, age, id, birthdate);
                    citizensAndRebels.Add(citizen);
                }
            }

            string input = Console.ReadLine();

            while (input != "End")
            {
                IBuyer citizenOrRebel = citizensAndRebels.FirstOrDefault(n => n.Name == input);
                if (citizenOrRebel != null)
                {
                    citizenOrRebel.BuyFood();
                }

                input = Console.ReadLine();
            }

            int totalFood = citizensAndRebels.Sum(n => n.Food);

            Console.WriteLine(totalFood);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: MartiHr/Softuni
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            List <IBuyer> buyers = new List <IBuyer>();

            for (int i = 0; i < n; i++)
            {
                string[] elements = Console.ReadLine()
                                    .Split(" ");

                if (elements.Length == 4)
                {
                    IBuyer currentCitizen = new Citizen(elements[0], int.Parse(elements[1]), elements[2], elements[3]);
                    buyers.Add(currentCitizen);
                }
                else
                {
                    IBuyer currentRebel = new Rebel(elements[0], int.Parse(elements[1]), elements[2]);
                    buyers.Add(currentRebel);
                }
            }

            string command = string.Empty;


            while ((command = Console.ReadLine()) != "End")
            {
                foreach (var buyer in buyers)
                {
                    if (buyer.Name == command)
                    {
                        buyer.BuyFood();
                    }
                }
            }

            int total = 0;

            foreach (var buyer in buyers)
            {
                total += buyer.Food;
            }

            Console.WriteLine(total);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: MiBuena/SoftUniCourses
        static void Main(string[] args)
        {
            List <IBuyer> buyersCollection = new List <IBuyer>();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] parameters = Console.ReadLine().Split(' ');

                if (parameters.Length == 4)
                {
                    Citizen citizen = new Citizen(parameters[0]);
                    buyersCollection.Add(citizen);
                }
                else
                {
                    Rebel rebel = new Rebel(parameters[0]);

                    buyersCollection.Add(rebel);
                }
            }

            while (true)
            {
                string command = Console.ReadLine().Trim();

                if (command == "End")
                {
                    break;
                }

                IBuyer buyer = buyersCollection.FirstOrDefault(x => x.Name == command);

                if (buyer != null)
                {
                    buyer.BuyFood();
                }
            }

            Console.WriteLine(buyersCollection.Sum(x => x.Food));
        }