Exemple #1
0
        static void Main(string[] args)
        {
            City city = new City();

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

            while (n-- > 0)
            {
                string[] tokens = Console.ReadLine().Split();
                if (tokens.Length == 4)
                {
                    string name      = tokens[0];
                    int    age       = int.Parse(tokens[1]);
                    string id        = tokens[2];
                    string birthdate = tokens[3];

                    Citizen citizen = new Citizen(name, age, id, birthdate);
                    city.AddCitizen(citizen);
                }
                else if (tokens.Length == 3)
                {
                    string name  = tokens[0];
                    int    age   = int.Parse(tokens[1]);
                    string group = tokens[2];

                    Rebel rebel = new Rebel(name, age, group);
                    city.AddRebel(rebel);
                }
            }

            while (true)
            {
                string name = Console.ReadLine();
                if (name == "End")
                {
                    break;
                }

                if (city.Rebels.Any(r => r.Name == name))
                {
                    Rebel rebel = city.Rebels.First(r => r.Name == name);
                    rebel.BuyFood();
                }

                if (city.Citizens.Any(c => c.Name == name))
                {
                    Citizen citizen = city.Citizens.First(c => c.Name == name);
                    citizen.BuyFood();
                }
            }

            Console.WriteLine(city.Rebels.Sum(r => r.Food) + city.Citizens.Sum(c => c.Food));
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            int lines = int.Parse(Console.ReadLine());

            HashSet <IBuyer> persons = new HashSet <IBuyer>();

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

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

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

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

                    Citizen citizen = citizen = new Citizen(name, age, id, birthdate);

                    persons.Add(citizen);
                }
            }

            string names = Console.ReadLine();

            while (names != "End")
            {
                var targetPerson = persons.FirstOrDefault(x => x.Name == names);

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

                names = Console.ReadLine();
            }

            var result = persons.Select(x => x.Food).Sum();

            Console.WriteLine(result);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>();

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

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

                IBuyer buyer = null;

                if (info.Length == 3)
                {
                    buyer = new Rebel(info[0], int.Parse(info[1]), info[2]);
                }
                else
                {
                    buyer = new Citizen(info[0], int.Parse(info[1]), info[2], info[3]);
                }

                buyers.Add(info[0], buyer);
            }

            string name = Console.ReadLine();

            while (name != "End")
            {
                if (buyers.ContainsKey(name))
                {
                    buyers[name].BuyFood();
                }

                name = Console.ReadLine();
            }

            int totalFood = buyers.Values.Select(x => x.Food).Sum();

            Console.WriteLine(totalFood);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>();
            int numbers = int.Parse(Console.ReadLine());

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

                if (inputInfo.Length == 3)
                {
                    string name  = inputInfo[0];
                    IBuyer rebel = new Rebel(name, int.Parse(inputInfo[1]), inputInfo[2]);
                    buyers.Add(name, rebel);
                }

                else
                {
                    string name    = inputInfo[0];
                    IBuyer citizen = new Citizen(name, int.Parse(inputInfo[1]), inputInfo[2], inputInfo[3]);
                    buyers.Add(name, citizen);
                }
            }

            string inputName = String.Empty;

            while ((inputName = Console.ReadLine()) != "End")
            {
                IBuyer buyer = buyers.FirstOrDefault(x => x.Key == inputName).Value;

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

            int food = buyers.Sum(x => x.Value.Food);

            Console.WriteLine(food);
        }