예제 #1
0
        static void Main(string[] args)
        {
            List <IBuyer> buyers = new List <IBuyer>();
            int           number = int.Parse(Console.ReadLine());

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

            string name = Console.ReadLine();

            while (name != "End")
            {
                if (buyers.Select(b => b.Name).Contains(name))
                {
                    buyers.FirstOrDefault(b => b.Name == name).BuyFood();
                }

                name = Console.ReadLine();
            }

            Console.WriteLine(buyers.Sum(b => b.Food));
        }
        static void Main(string[] args)
        {
            Dictionary <string, IBuyer> members = new Dictionary <string, IBuyer>();

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

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

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

            string comand;

            while ((comand = Console.ReadLine()) != "End")
            {
                if (members.ContainsKey(comand))
                {
                    members[comand].BuyFood();
                }
            }

            int foodSum = members.Sum(p => p.Value.Food);

            Console.WriteLine(foodSum);
        }
예제 #3
0
        private static void CreateRebel(List <Rebel> rebels, string[] personInfo, string personName, int age)
        {
            string group = personInfo[2];

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

            rebels.Add(rebel);
        }
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>();

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

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

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

                    buyers[name] = new Rebel(name, age, group);
                }
            }



            while (true)
            {
                string name = Console.ReadLine();

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

                if (!buyers.ContainsKey(name))
                {
                    continue;
                }

                IBuyer buyer = buyers[name];

                buyer.BuyFood();
            }

            var total = buyers.Values.Sum(b => b.Food);

            Console.WriteLine(total);
        }
예제 #5
0
        public static void Main(string[] args)
        {
            Dictionary <string, IBuyer> buyersByName = new Dictionary <string, IBuyer>();

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

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

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

                    buyersByName[name] = new Rebel(name, age, group);
                }
                else
                {
                    string name      = data[0];
                    int    age       = int.Parse(data[1]);
                    string id        = data[2];
                    string birthdate = data[3];

                    buyersByName[name] = new Citizen(name, age, id, birthdate);
                }
            }

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

                if (!buyersByName.ContainsKey(line))
                {
                    continue;
                }

                IBuyer buyer = buyersByName[line];
                buyer.BuyFood();
            }

            var totalAmountFood = buyersByName.Values.Sum(b => b.Food);

            Console.WriteLine(totalAmountFood);
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dictionary <string, IBuyer> birthablesByName = new Dictionary <string, IBuyer>();

            for (int i = 0; i < n; i++)
            {
                string[] parts = Console.ReadLine().Split(" ");
                if (parts.Length == 4)
                {
                    string name      = parts[0];
                    int    age       = int.Parse(parts[1]);
                    string id        = parts[2];
                    string birthdate = parts[3];
                    birthablesByName[name] = new Citizen(name, age, id, birthdate);
                }
                else
                {
                    string name  = parts[0];
                    int    age   = int.Parse(parts[1]);
                    string group = parts[2];
                    birthablesByName[name] = new Rebel(name, age, group);
                }
            }

            while (true)
            {
                string name = Console.ReadLine();

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

                if (!birthablesByName.ContainsKey(name))
                {
                    continue;
                }

                IBuyer buyer = birthablesByName[name];

                buyer.BuyFood();
            }

            var total = birthablesByName.Values.Sum(x => x.Food);

            Console.WriteLine(total);
        }
예제 #7
0
        public static void Main()
        {
            List <IPerson> result = new List <IPerson>();
            int            n      = int.Parse(Console.ReadLine());

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

                if (parts.Length == 3)
                {
                    IPerson rebel = new Rebel(parts[0], int.Parse(parts[1]), parts[2]);
                    result.Add(rebel);
                }
                else if (parts.Length == 4)
                {
                    IPerson citizen = new Citizen(parts[0], int.Parse(parts[1]), parts[2], parts[3]);
                    result.Add(citizen);
                }
            }

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

                foreach (var names in result)
                {
                    if (names.Name == name)
                    {
                        names.BuyFood();
                    }
                }
            }
            int food = 0;

            foreach (var item in result)
            {
                food += item.Food;
            }
            Console.WriteLine(food);
        }
예제 #8
0
        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[] objects = Console.ReadLine().Split();

                if (objects.Length == 3)
                {
                    Rebel rebel = new Rebel(objects[0], int.Parse(objects[1]), objects[2]);
                    buyers.Add(rebel);
                }
                else
                {
                    Citizen citizen = new Citizen(objects[0], int.Parse(objects[1]), objects[2], objects[3]);
                    buyers.Add(citizen);
                }
            }

            string input = Console.ReadLine();

            while (input != "End")
            {
                if (buyers.Exists(x => x.Name == input))
                {
                    buyers.FirstOrDefault(x => x.Name == input).BuyFood();
                }

                input = Console.ReadLine();
            }

            int foodTotal = 0;

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

            Console.WriteLine(foodTotal);
        }
예제 #9
0
        static void Main(string[] args)
        {
            List <Citizen> citizens = new List <Citizen>();
            List <Rebel>   rebels   = new List <Rebel>();
            var            n        = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split();
                if (input.Length == 4)
                {
                    var citizen = new Citizen(input[0], int.Parse(input[1]), input[2], input[3]);
                    citizens.Add(citizen);
                }
                if (input.Length == 3)
                {
                    var rebel = new Rebel(input[0], int.Parse(input[1]), input[2]);
                    rebels.Add(rebel);
                }
            }
            var    totalFood = 0;
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                var person = citizens.Where(p => p.Name == command).FirstOrDefault();
                if (person != null)
                {
                    person.BuyFood();
                    totalFood += 10;
                }
                var reb = rebels.Where(p => p.Name == command).FirstOrDefault();
                if (reb != null)
                {
                    reb.BuyFood();
                    totalFood += 5;
                }
            }
            Console.WriteLine(totalFood);
        }
예제 #10
0
        static void Main(string[] args)
        {
            Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>();

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

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

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

            while (true)
            {
                string name = Console.ReadLine();

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

                if (buyers.ContainsKey(name))
                {
                    IBuyer currentBuyer = buyers[name];
                    currentBuyer.BuyFood();
                }
            }

            Console.WriteLine(buyers.Values.Sum(x => x.Food));
        }
예제 #11
0
        static void Main(string[] args)
        {
            Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>();

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

            for (int i = 0; i < n; i++)
            {
                string[] current = Console.ReadLine()
                                   .Split(' ', StringSplitOptions.RemoveEmptyEntries);
                //Pesho 25 8904041303 04/04/1989
                //Stancho 27 WildMonkeys
                string name = current[0];
                int    age  = int.Parse(current[1]);

                if (current.Length == 3)
                {
                    buyers[name] = new Rebel(name, age, current[2]);
                }
                else if (current.Length == 4)
                {
                    buyers[name] = new Citizen(name, age, current[2], current[3]);
                }
            }

            string cmd = Console.ReadLine();

            while (cmd != "End")
            {
                if (buyers.ContainsKey(cmd))
                {
                    buyers[cmd].BuyFood();
                }
                cmd = Console.ReadLine();
            }
            Console.WriteLine(buyers.Values.Sum(b => b.Food));
        }