public static void Main()
    {
        var inhabitantsCount = int.Parse(Console.ReadLine());
        var name             = string.Empty;
        var age = 0;

        var buyers = new HashSet <IBuyer>();

        for (int i = 0; i < inhabitantsCount; i++)
        {
            var inhabitantInfo = Console.ReadLine().Split(' ');

            if (inhabitantInfo.Length == 4)
            {
                name = inhabitantInfo[0];
                age  = int.Parse(inhabitantInfo[1]);
                var id        = inhabitantInfo[2];
                var birthdate = inhabitantInfo[3];

                Citizen citizen = new Citizen(name, age, id, birthdate);
                citizen.BuyFood();
                buyers.Add(citizen);
            }
            else
            {
                name = inhabitantInfo[0];
                age  = int.Parse(inhabitantInfo[1]);
                var group = inhabitantInfo[2];

                Rebel rebel = new Rebel(name, age, group);
                rebel.BuyFood();
                buyers.Add(rebel);
            }
        }

        var totalAmount = 0;

        var line = Console.ReadLine();

        while (!line.Equals("End"))
        {
            var currentBuyerName = line;

            var personExists = buyers.Any(b => b.Name.Equals(currentBuyerName));

            if (personExists)
            {
                var buyer = buyers.FirstOrDefault(b => b.Name.Equals(currentBuyerName));
                totalAmount += buyer.Food;
            }

            line = Console.ReadLine();
        }

        Console.WriteLine(totalAmount);
    }
Пример #2
0
        public void Run()
        {
            List <Citizen> citizens = new List <Citizen>();
            List <Rebel>   rebels   = new List <Rebel>();
            DateTime       DATE     = new DateTime(2015, 02, 03);
            //int n = int.Parse(Console.ReadLine());
            int totalAmount = 0;

            //for (int i = 0; i < n; i++)
            //{
            //    string command = Console.ReadLine();
            //    string[] tokens = command.Split();
            //    if (tokens.Length == 4)
            //    {
            //        string[] date = tokens[3].Split('/');
            //        DateTime thisBirthdate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]));
            //        Citizen citizen = new Citizen(tokens[0], int.Parse(tokens[1]), tokens[2], thisBirthdate);
            //        citizens.Add(citizen);
            //    }
            //    else if (tokens.Length == 3)
            //    {

            //        Rebel rebel = new Rebel(tokens[0], int.Parse(tokens[1]), tokens[2]);
            //        rebels.Add(rebel);

            //    }

            //}

            while (true)
            {
                string buyer = Console.ReadLine();
                if (buyer == "End")
                {
                    break;
                }
                if (citizens.Any(x => x.Name == buyer))
                {
                    Citizen current = citizens.Where(x => x.Name == buyer).FirstOrDefault();
                    current.BuyFood();
                    totalAmount += 10;
                }
                else if (rebels.Any(x => x.Name == buyer))
                {
                    Rebel current = rebels.Where(x => x.Name == buyer).FirstOrDefault();
                    current.BuyFood();
                    totalAmount += 5;
                }
            }
            DateTime date = new DateTime(Console.ReadLine());

            Console.WriteLine(totalAmount);
        }
Пример #3
0
        static void Main(string[] args)
        {
            List <Society> list = new List <Society>();

            string[] info;
            int      totalFood = 0;
            int      number    = int.Parse(Console.ReadLine());

            for (int i = 0; i < number; i++)
            {
                info = Console.ReadLine().Split(' ');
                if (info.Length == 4)
                {
                    Citizen citizen = new Citizen(info[0], int.Parse(info[1]), info[2], info[3]);
                    list.Add(citizen);
                    citizen.BuyFood();
                }
                else if (info.Length == 3)
                {
                    Rebel rebel = new Rebel(info[0], int.Parse(info[1]), info[2]);
                    list.Add(rebel);
                    rebel.BuyFood();
                }
            }
            string names;

            do
            {
                names = Console.ReadLine();
                if (names == "End")
                {
                    break;
                }
                foreach (var i in list)
                {
                    if (names == i.Name)
                    {
                        totalFood += i.Food;
                        break;
                    }
                }
            } while (names != "End");

            Console.WriteLine(totalFood);
            Console.ReadKey();
        }
Пример #4
0
        static void Main(string[] args)
        {
            People people      = new People();
            int    peopleCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < peopleCount; i++)
            {
                string[] inputArgs = Console.ReadLine().Split();
                if (inputArgs.Length == 3)
                {
                    string name  = inputArgs[0];
                    int    age   = int.Parse(inputArgs[1]);
                    string group = inputArgs[2];
                    Rebel  rebel = new Rebel(name, age, group);
                    people.AddRebel(rebel);
                }
                else if (inputArgs.Length == 4)
                {
                    string  name      = inputArgs[0];
                    int     age       = int.Parse(inputArgs[1]);
                    string  id        = inputArgs[2];
                    string  birthdate = inputArgs[3];
                    Citizen citizen   = new Citizen(name, age, id, birthdate);
                    people.AddCitizen(citizen);
                }
            }
            string nameToFind;

            while ((nameToFind = Console.ReadLine()) != "End")
            {
                if (people.Citizens.Any(x => x.Name == nameToFind))
                {
                    Citizen citizen = people.Citizens.First(x => x.Name == nameToFind);
                    citizen.BuyFood();
                }
                else if (people.Rebels.Any(x => x.Name == nameToFind))
                {
                    Rebel rebel = people.Rebels.First(x => x.Name == nameToFind);
                    rebel.BuyFood();
                }
            }
            int food = people.Rebels.Sum(x => x.Food) + people.Citizens.Sum(x => x.Food);

            Console.WriteLine(food);
        }