예제 #1
0
        static void Main(string[] args)
        {
            List <Rebel>   rebels   = new List <Rebel>();
            List <Citizen> citizens = new List <Citizen>();

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

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

                if (currentPerson.Length == 3)
                {
                    //<name> <age><group>

                    string name  = currentPerson[0];
                    int    age   = int.Parse(currentPerson[1]);
                    string group = currentPerson[2];

                    Rebel person = new Rebel(name, age, group);
                    rebels.Add(person);
                }

                if (currentPerson.Length == 4)
                {
                    //<name> <age> <id> <birthdate>

                    string name      = currentPerson[0];
                    int    age       = int.Parse(currentPerson[1]);
                    string id        = currentPerson[2];
                    string birthdate = currentPerson[3];

                    Citizen person = new Citizen(name, age, id, birthdate);
                    citizens.Add(person);
                }
            }

            string currentName = Console.ReadLine();

            while (currentName != "End")
            {
                if (rebels.Any(x => x.Name == currentName))
                {
                    Rebel currentRebel = rebels.FirstOrDefault(x => x.Name == currentName);
                    currentRebel.BuyFood();
                }

                if (citizens.Any(x => x.Name == currentName))
                {
                    Citizen currentCitizen = citizens.FirstOrDefault(x => x.Name == currentName);
                    currentCitizen.BuyFood();
                }

                currentName = Console.ReadLine();
            }

            int totalFood = citizens.Sum(x => x.Food) + rebels.Sum(x => x.Food);

            Console.WriteLine(totalFood);
        }
예제 #2
0
        static void Main(string[] args)
        {
            HashSet <Citizen> citizens = new HashSet <Citizen>();
            HashSet <Rebel>   rebels   = new HashSet <Rebel>();


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

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

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

                    Citizen citizen = new Citizen(name, age, id);
                    citizens.Add(citizen);
                }
                else
                {
                    string name  = cmdArgs[0];
                    int    age   = int.Parse(cmdArgs[1]);
                    string group = cmdArgs[2];

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

            string command;
            int    allFood = 0;

            while ((command = Console.ReadLine()) != "End")
            {
                string name = command;

                foreach (var citizen in citizens)
                {
                    if (citizen.Name == name)
                    {
                        citizen.BuyFood();
                        allFood += 10;
                    }
                }

                foreach (var rebel in rebels)
                {
                    if (rebel.Name == name)
                    {
                        rebel.BuyFood();
                        allFood += 5;
                    }
                }
            }
            Console.WriteLine(allFood);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            List <IPerson> society = new List <IPerson>();

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

            for (int i = 0; i < n; i++)
            {
                string[] data = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
                if (data.Length == 4)
                {
                    IPerson citizen = new Citizen(data[0], data[1], data[2], data[3]);
                    society.Add(citizen);
                }
                else if (data.Length == 3)
                {
                    IPerson rebel = new Rebel(data[0], data[1], data[2]);
                    society.Add(rebel);
                }
            }

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                var curentBuyer = society.FirstOrDefault(c => c.Name == input);
                if (curentBuyer != null)
                {
                    curentBuyer.BuyFood();
                }
            }
            Console.WriteLine(society.Sum(p => p.Food));
        }
예제 #4
0
        static void Main(string[] args)
        {
            List <IBuyer> buyers          = new List <IBuyer>();
            int           numberOfMembers = int.Parse(Console.ReadLine());

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

            while ((operation = Console.ReadLine()) != "End")
            {
                if (buyers.FirstOrDefault(x => x.Name == operation) != null)
                {
                    buyers.First(x => x.Name == operation).BuyFood();
                }
            }
            Console.WriteLine(buyers.Sum(x => x.Food));
        }
예제 #5
0
        static void Main(string[] args)
        {
            List <ITownsman>  townsmenList   = new List <ITownsman>();
            List <IBirthdate> birthdatesList = new List <IBirthdate>();
            List <IBuyer>     buyers         = new List <IBuyer>();
            var repeat = int.Parse(Console.ReadLine());

            for (int i = 0; i < repeat; i++)

            {
                var inputCommand = Console.ReadLine();
                var inputData    = inputCommand
                                   .Split(new[] { ' ' });
                string iD;
                string birthdate;
                switch (inputData.Length)
                {
                case 4:
                    var name = inputData[0];
                    var age  = int.Parse(inputData[1]);
                    iD        = inputData[2];
                    birthdate = inputData[3];
                    Citizen citizen = new Citizen(name, age, iD, birthdate);
                    townsmenList.Add(citizen);
                    birthdatesList.Add(citizen);
                    buyers.Add(citizen);
                    break;

                case 3:
                    var   rebelName = inputData[0];
                    var   rabelAge  = int.Parse(inputData[1]);
                    var   group     = inputData[2];
                    Rebel rebel     = new Rebel(rebelName, rabelAge, group);
                    buyers.Add(rebel);

                    break;

                default:
                    break;
                }
            }

            do
            {
                var inputCommand = Console.ReadLine();
                if (inputCommand == "End")
                {
                    break;
                }

                if (buyers.Any(x => x.Name == inputCommand))
                {
                    var index = buyers.FindIndex(x => x.Name == inputCommand);
                    buyers[index].BuyFood();
                }
            } while (true);

            Console.WriteLine(buyers.Sum(x => x.Food));
        }
예제 #6
0
        static void Main(string[] args)
        {
            var visitorsList = new List <IInterface>();
            var humanoids    = new List <IBuyer>();


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

            for (int i = 0; i < num; i++)
            {
                string[] input = Console.ReadLine().Split();
                if (input.Length == 4)
                {
                    if (humanoids.Any(x => x.Name == input[0]))
                    {
                        continue;
                    }
                    name     = input[0];
                    age      = int.Parse(input[1]);
                    id       = input[2];
                    birthday = input[3];

                    var citizen = new Citizen(name, age, id, birthday);
                    humanoids.Add(citizen);
                }
                else
                {
                    if (humanoids.Any(x => x.Name == input[0]))
                    {
                        continue;
                    }
                    name = input[0];
                    age  = int.Parse(input[1]);
                    string group = input[2];
                    var    rebel = new Rebel(name, age, group);
                    humanoids.Add(rebel);
                }
            }
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                if (humanoids.Any(x => x.Name == command))
                {
                    var current = humanoids.FirstOrDefault(x => x.Name == command);
                    current.BuyFood();
                }
            }
            int result = 0;

            foreach (var item in humanoids)
            {
                result += item.Food;
            }
            Console.WriteLine(result);
        }
예제 #7
0
        public static void LackOfFood()
        {
            List <IBuyer> listOfBuyers = new List <IBuyer>();
            List <string> listOfNames  = new List <string>();

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

            for (int i = 0; i < count; i++)
            {
                string        input_  = Console.ReadLine();
                List <string> tokens_ = input_.Split().ToList();
                switch (tokens_.Count)
                {
                case 4:
                    IBuyer citizenBuyer = new Citizen(tokens_[2], int.Parse(tokens_[1]), tokens_[0], tokens_[3]);
                    listOfNames.Add(tokens_[0]);
                    listOfBuyers.Add(citizenBuyer);
                    break;

                case 3:
                    IBuyer rebelBuyer = new Rebel(int.Parse(tokens_[1]), tokens_[0], tokens_[2]);
                    listOfBuyers.Add(rebelBuyer);
                    listOfNames.Add(tokens_[0]);
                    break;
                }
            }

            string inputName = Console.ReadLine();

            while (inputName != "End")
            {
                for (int i = 0; i < listOfNames.Count; i++)
                {
                    if (listOfNames[i] == inputName)
                    {
                        listOfBuyers[i].BuyFood();
                    }
                }

                inputName = Console.ReadLine();
            }

            int outPut = 0;

            foreach (var item in listOfBuyers)
            {
                outPut += item.Food;
            }

            Console.WriteLine(outPut);
        }
예제 #8
0
        static void Main(string[] args)
        {
            Dictionary <string, IBuyer> all = new Dictionary <string, IBuyer>();

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

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

                string name = line[0];
                int    age  = int.Parse(line[1]);

                if (all.ContainsKey(name))
                {
                    continue;
                }

                if (line.Length == 4)
                {
                    string id       = line[2];
                    string birthade = line[3];

                    IBuyer citzen = new Citizen(name, age, id, birthade);

                    all.Add(name, citzen);
                }
                else if (line.Length == 3)
                {
                    string group = line[2];

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

                    all.Add(name, rebel);
                }
            }

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                string name = command;
                if (all.Any(x => x.Key == name))
                {
                    all[name].BuyFood();
                }
            }

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

            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(" ");
                if (input.Length == 3)
                {
                    var rebel = new Rebel(input[0], int.Parse(input[1]), input[2]);
                    rebels.Add(rebel);
                }
                else
                {
                    var Citizen = new Citizen(input[0], int.Parse(input[1]), input[2], input[3]);
                    citizens.Add(Citizen);
                }
            }
            string name      = Console.ReadLine();
            var    Totalfood = new HashSet <IBuyer>();

            while (name != "End")
            {
                if (name == "End")
                {
                    break;
                }
                var citizen = citizens.FirstOrDefault(x => x.Name == name);
                var rebel   = rebels.FirstOrDefault(x => x.Name == name);
                if (citizen != null)
                {
                    citizen.BuyFood();
                    Totalfood.Add(citizen);
                }
                else if (rebel != null)
                {
                    rebel.BuyFood();
                    Totalfood.Add(rebel);
                }
                name = Console.ReadLine();
            }
            int food = 0;

            foreach (var item in Totalfood)
            {
                food += item.Food;
            }
            Console.WriteLine(food);
        }
예제 #10
0
        static void Main(string[] args)
        {
            List <IBuyer> buyers = new List <IBuyer>();
            int           n      = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var tokens = Console.ReadLine().Split(" ");

                if (tokens.Length == 4)
                {
                    Citizen citizen = new Citizen(tokens[0], int.Parse(tokens[1]), tokens[2], tokens[3]);
                    buyers.Add(citizen);
                }

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

            string input = Console.ReadLine();

            while (input != "End")
            {
                var person = buyers.FirstOrDefault(p => p.Name == input);

                if (person == null)
                {
                    input = Console.ReadLine();
                    continue;
                }

                person.BuyFood();


                input = Console.ReadLine();
            }

            int allFood = 0;

            foreach (var f in buyers)
            {
                allFood += f.Food;
            }

            Console.WriteLine(allFood);
        }
예제 #11
0
파일: Program.cs 프로젝트: dstoteva/CS-OOP
        static void Main(string[] args)
        {
            var buyers = new List <IBuyer>();

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

            for (int i = 0; i < n; i++)
            {
                string[] buyersArgs = Console.ReadLine().Split();
                string   name       = buyersArgs[0];
                int      age        = int.Parse(buyersArgs[1]);
                if (buyersArgs.Length == 3)
                {
                    string group = buyersArgs[2];
                    var    rebel = new Rebel(name, age, group);
                    buyers.Add(rebel);
                }
                else
                {
                    string id        = buyersArgs[2];
                    string birthDate = buyersArgs[3];
                    var    citizen   = new Citizen(name, age, id, birthDate);
                    buyers.Add(citizen);
                }
            }
            while (true)
            {
                string name = Console.ReadLine();

                if (name == "End")
                {
                    break;
                }
                foreach (var b in buyers)
                {
                    if (b.Name == name)
                    {
                        b.BuyFood();
                    }
                }
            }
            int food = 0;

            foreach (var b in buyers)
            {
                food += b.Food;
            }
            Console.WriteLine(food);
        }
예제 #12
0
        public static void Main(string[] args)
        {
            int           n      = int.Parse(Console.ReadLine());
            List <IBuyer> result = new List <IBuyer>();

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

                switch (input.Length)
                {
                case 4:
                    string name      = input[0];
                    string age       = input[1];
                    string id        = input[2];
                    string birthdate = input[3];

                    Citizen citizen = new Citizen(name, age, id, birthdate);
                    result.Add(citizen);
                    break;

                case 3:
                    string rebelName  = input[0];
                    string rebelAge   = input[1];
                    string rebelGroup = input[2];

                    Rebel rebel = new Rebel(rebelName, rebelAge, rebelGroup);
                    result.Add(rebel);
                    break;
                }
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                string name = command;

                if (result.Any(x => x.Name == name))
                {
                    IBuyer item = result.FirstOrDefault(x => x.Name == name);
                    item.BuyFood();
                }

                command = Console.ReadLine();
            }

            Console.WriteLine(result.Sum(x => x.Food));
        }
예제 #13
0
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());

            while (n > 0)
            {
                var input = Console.ReadLine();

                var args      = input.Split();
                var name      = "";
                var age       = 0;
                var id        = "";
                var birthdate = "";
                var group     = "";

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

                    var cit = new Citizen(name, age, id, birthdate);
                    entities.Add(cit);
                }
                else if (args.Length == 3)
                {
                    name  = args[0];
                    age   = int.Parse(args[1]);
                    group = args[2];

                    var rebel = new Rebel(name, age, group);
                    entities.Add(rebel);
                }
                n--;
            }

            var command = "";

            while ((command = Console.ReadLine()) != "End")
            {
                if (entities.Any(e => e.Name == command))
                {
                    entities.Where(e => e.Name == command).First().BuyFood();
                }
            }

            Console.WriteLine(TotalFood);
        }
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            var people = new List <IBuyer>();

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

                string name = personInfo[0];
                int    age  = int.Parse(personInfo[1]);

                if (personInfo.Length == 4)
                {
                    string id        = personInfo[2];
                    string birthDate = personInfo[3];

                    var newCitizen = new Citizen(name, age, id, birthDate);
                    people.Add(newCitizen);
                }
                else if (personInfo.Length == 3)
                {
                    string group = personInfo[2];

                    var newRebel = new Rebel(name, age, group);
                    people.Add(newRebel);
                }
            }

            string personBuyingFoodName = Console.ReadLine();

            while (personBuyingFoodName != "End")
            {
                var buyer = FindBuyer(personBuyingFoodName, people);

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

                personBuyingFoodName = Console.ReadLine();
            }

            int totalFoodBought = CalculateTotalFoodBought(people);

            Console.WriteLine(totalFoodBought);
        }
예제 #15
0
        public void Run()
        {
            List <Citizen> citizens = new List <Citizen>();

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

            for (int i = 0; i < peopeCount; i++)
            {
                string[] citizenArguments = Console.ReadLine().Split(" ");
                string   name             = citizenArguments[0];
                int      age = int.Parse(citizenArguments[1]);

                if (citizenArguments.Length == 4)
                {
                    string   id        = citizenArguments[2];
                    DateTime birthdate = DateTime.ParseExact(citizenArguments[3], "dd/MM/yyyy", null);

                    Person person = new Person(name, age, id, birthdate);

                    citizens.Add(person);
                }
                else if (citizenArguments.Length == 3)
                {
                    string group = citizenArguments[2];

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

                    citizens.Add(rebel);
                }
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                Citizen currentCitizen = citizens.FirstOrDefault(x => x.Name == command);

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

                command = Console.ReadLine();
            }

            Console.WriteLine(citizens.Sum(x => x.Food));
        }
예제 #16
0
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var citizens = new List <Citizen>();
            var rebels   = new List <Rebel>();

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

            var input = Console.ReadLine();
            var sum   = 0;

            while (input != "End")
            {
                foreach (var citizen in citizens)
                {
                    if (citizen.Name == input)
                    {
                        citizen.BuyFood();
                    }
                }
                foreach (var rebel in rebels)
                {
                    if (rebel.Name == input)
                    {
                        rebel.BuyFood();
                    }
                }
                input = Console.ReadLine();
            }

            Console.WriteLine(citizens.Sum(b => b.Food) + rebels.Sum(b => b.Food));
        }
예제 #17
0
        static void Main(string[] args)
        {
            int numberOfNames = int.Parse(Console.ReadLine());

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

            for (int i = 0; i < numberOfNames; i++)
            {
                string[] input = Console.ReadLine().Split();
                string   name  = input[0];
                string   age   = input[1];

                if (input.Length == 3)
                {
                    string group = input[2];

                    Rebel rebel = new Rebel(name, age, group);
                    buyers.Add(rebel);
                }
                else if (input.Length == 4)
                {
                    string id       = input[2];
                    string birthDay = input[3];

                    Citizen citizen = new Citizen(name, age, id, birthDay);
                    buyers.Add(citizen);
                }
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                IBuyer buyer = buyers.FirstOrDefault(b => b.Name == command);

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

            int sum = buyers.Sum(b => b.Food);

            Console.WriteLine(sum);
        }
예제 #18
0
        static void Main(string[] args)
        {
            List <IName> citizens = new List <IName>();
            int          n        = int.Parse(Console.ReadLine());

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

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


            string names;

            while ((names = Console.ReadLine()) != "End")
            {
                for (int i = 0; i < citizens.Count; i++)
                {
                    if (citizens[i].Name == names)
                    {
                        citizens[i].BuyFood();
                    }
                }
            }
            var totalFood = citizens
                            .Where(x => x.Food != 0)
                            .ToList();
            var total = 0;

            foreach (var item in totalFood)
            {
                total += item.Food;
            }
            Console.WriteLine(total);
        }
예제 #19
0
        private static void FeedInput(string[] inputData)
        {
            switch (inputData.Length)
            {
            case 3:
                Rebel rebel = new Rebel(inputData[0], int.Parse(inputData[1]), inputData[2]);
                identifiabls.Add(rebel);
                break;

            case 4:
                Citizen citizen = new Citizen(inputData[0], int.Parse(inputData[1]), inputData[2], inputData[3]);
                identifiabls.Add(citizen);
                break;

            default:
                break;
            }
        }
예제 #20
0
        static void Main(string[] args)
        {
            List <IBuyer> buyers = new List <IBuyer>();

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

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

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

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                IBuyer buyer = buyers.Where(b => b.Name == command).FirstOrDefault();

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

            int foodPurchased = 0;

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

            Console.WriteLine(foodPurchased);
        }
예제 #21
0
        static void Main(string[] args)
        {
            List <IBuyer> buyers = new List <IBuyer>();
            int           n      = int.Parse(Console.ReadLine());

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

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

            string input = Console.ReadLine();
            int    sum   = 0;

            while (input != "End")
            {
                foreach (var b in buyers)
                {
                    if (b.Name == input)

                    {
                        b.BuyFood();
                        sum += b.Food;
                    }
                }

                input = Console.ReadLine();
            }

            Console.WriteLine(sum);
        }
예제 #22
0
        public static void Main()
        {
            List <IBuyer> citizens    = new List <IBuyer>();
            int           buyersCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < buyersCount; i++)
            {
                string[] tokens = Console.ReadLine().Split();
                if (tokens.Length == 3)
                {
                    string name  = tokens[0];
                    int    age   = int.Parse(tokens[1]);
                    string group = tokens[2];
                    IBuyer rebel = new Rebel(name, age, group);
                    citizens.Add(rebel);
                }
                else if (tokens.Length == 4)
                {
                    string name     = tokens[0];
                    int    age      = int.Parse(tokens[1]);
                    string id       = tokens[2];
                    string birthday = tokens[3];
                    IBuyer citizen  = new Citizen(name, age, id, birthday);
                    citizens.Add(citizen);
                }
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                if (citizens.Any(c => c.Name == command))
                {
                    citizens.First(c => c.Name == command).BuyFood();
                }

                command = Console.ReadLine();
            }

            Console.WriteLine(citizens.Sum(c => c.Food));
        }
예제 #23
0
        public static void Main()
        {
            List <IBuyer> citizensAndRebels = new List <IBuyer>();

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

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

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

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

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

                IBuyer buyer = citizensAndRebels.FirstOrDefault(x => x.Name == name);

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

            Console.WriteLine(citizensAndRebels.Sum(x => x.Food));
        }
예제 #24
0
        private static void FoodShortage()
        {
            int           lines  = int.Parse(Console.ReadLine());
            List <IBuyer> buyers = new List <IBuyer>();

            for (int line = 0; line < lines; line++)
            {
                string input    = Console.ReadLine();
                var    splitted = input.Split(" ");

                if (splitted.Length == 3) // rebel
                {
                    Rebel rebel = new Rebel(splitted[0]);
                    buyers.Add(rebel);
                }
                else if (splitted.Length == 4) // citizen
                {
                    Citizen citizen = new Citizen(splitted[0]);
                    buyers.Add(citizen);
                }
            }

            string commandOrName = Console.ReadLine();

            while (commandOrName != "End")
            {
                IBuyer buyer = buyers.FirstOrDefault(b => b.Name == commandOrName);

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

                commandOrName = Console.ReadLine();
            }

            int total = buyers.Sum(b => b.Food);

            Console.WriteLine(total);
        }
        private static void ReadFromConsoleAddToHumans(Dictionary <string, IBuyer> humans, int inputHumanNumber)
        {
            for (int i = 0; i < inputHumanNumber; i++)
            {
                var input = Console.ReadLine().Split();

                if (input.Length == 4)
                {
                    var citizen = new Citizen(input[0], input[1], input[2], input[3]);
                    humans[input[0]] = citizen;
                }
                else if (input.Length == 3)
                {
                    var rebel = new Rebel(input[0], input[1], input[2]);
                    humans[input[0]] = rebel;
                }
                else
                {
                    // Invalid input, just skip it.
                }
            }
        }
예제 #26
0
        static void Main(string[] args)
        {
            string input;
            Dictionary <string, IBuyer> results = new Dictionary <string, IBuyer>();
            var ibuyers = int.Parse(Console.ReadLine());

            for (int i = 0; i < ibuyers; i++)
            {
                input = Console.ReadLine();
                var tokens = input.Split();
                if (tokens.Length == 4)
                {
                    Citizen citizen = new Citizen(tokens[0], int.Parse(tokens[1]), tokens[2], tokens[3]);
                    if (!results.ContainsKey(citizen.Name))
                    {
                        results.Add(citizen.Name, citizen);
                    }
                }
                else
                {
                    Rebel rebel = new Rebel(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    if (!results.ContainsKey(rebel.Name))
                    {
                        results.Add(rebel.Name, rebel);
                    }
                }
            }
            var totalFood = 0;

            while ((input = Console.ReadLine()) != "End")
            {
                if (results.ContainsKey(input))
                {
                    totalFood += results[input].BuyFood();
                }
            }
            Console.WriteLine(totalFood);
        }
예제 #27
0
        static void Main(string[] args)
        {
            List <IBuyer> buyers = new List <IBuyer>();
            int           n      = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split();
                string   name  = input[0];
                int      age   = int.Parse(input[1]);
                if (input.Length == 4)
                {
                    string  id        = input[2];
                    string  birthdate = input[3];
                    Citizen citizen   = new Citizen(name, age, id, birthdate);
                    buyers.Add(citizen);
                }
                else if (input.Length == 3)
                {
                    string group = input[2];
                    Rebel  rebel = new Rebel(name, age, group);
                    buyers.Add(rebel);
                }
            }
            string buyerName = default;

            while ((buyerName = Console.ReadLine().Replace(" ", string.Empty)).ToLower() != "end")
            {
                IBuyer buyer = buyers.FirstOrDefault(x => x.Name == buyerName);
                if (buyer != null)
                {
                    buyer.BuyFood();
                }
            }
            Console.WriteLine(buyers.Sum(x => x.Food));
        }
예제 #28
0
        static void Main(string[] args)
        {
            List <IBuyer> inhabitants = new List <IBuyer>();

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

            IBuyer inhabitant = null;

            for (int i = 0; i < n; i++)
            {
                string[] curInhabitant = Console.ReadLine().Split();
                if (curInhabitant.Length == 4)
                {
                    inhabitant = new Citizens(curInhabitant[0],
                                              int.Parse(curInhabitant[1]),
                                              curInhabitant[2],
                                              curInhabitant[3]);
                }
                else
                {
                    inhabitant = new Rebel(curInhabitant[0],
                                           int.Parse(curInhabitant[1]),
                                           curInhabitant[2]);
                }
                inhabitants.Add(inhabitant);
            }
            int    totalFood = 0;
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                inhabitant = inhabitants.FirstOrDefault(el => el.Name == command);
                if (inhabitant != null)
                {
                    IBuyer curPerson = (IBuyer)inhabitant;
                    curPerson.BuyFood();
                }
            }

            foreach (var item in inhabitants)
            {
                totalFood += item.Food;
            }
            Console.WriteLine(totalFood);

            //Task on 5.	Birthday Celebrations
            //string command;
            //while ((command = Console.ReadLine()) != "End")
            //{

            //    string[] curInhabitant = command.Split();
            //    IInhabitable inhabitant = null;
            //    if (curInhabitant[0] == "Citizen")
            //    {
            //        inhabitant = new Citizens(curInhabitant[1],
            //            int.Parse(curInhabitant[2]),
            //            curInhabitant[3],
            //            curInhabitant[4]);

            //    }
            //    else if (curInhabitant[0] == "Robot")
            //    {
            //        inhabitant = new Robot(curInhabitant[1],
            //            (curInhabitant[2]));

            //    }
            //    else if(curInhabitant[0] == "Pet")
            //    {
            //        inhabitant = new Pet(curInhabitant[1],
            //            (curInhabitant[2]));

            //    }

            //    inhabitants.Add(inhabitant);

            //}

            //string criteria = Console.ReadLine();

            //inhabitants.Where(el => el.Birthday != null)
            //    .ToList()
            //    .Where(el => el.Birthday.EndsWith(criteria))
            //    .ToList()
            //    .ForEach(el => Console.WriteLine(el.Birthday));
        }
예제 #29
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[] splited = Console.ReadLine().Split(' ');

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

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

                    buyers.Add(citizen);
                }
                else if (splited.Length == 3)
                {
                    string name  = splited[0];
                    int    age   = int.Parse(splited[1]);
                    string group = splited[2];

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

                    buyers.Add(rebel);
                }
            }

            string input = Console.ReadLine();

            while (input != "End")
            {
                IBuyer buyer = null;

                try
                {
                    buyer = buyers.FirstOrDefault(b => b.Name == input);

                    buyer.BuyFood();
                }
                catch (Exception)
                {
                    input = Console.ReadLine();
                    continue;
                }

                input = Console.ReadLine();
            }

            int food = 0;

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

            Console.WriteLine(food);
        }
예제 #30
0
        public static void Main(string[] args)
        {
            List <Citizen> citizens = new List <Citizen>();
            List <Rebel>   rebels   = new List <Rebel>();

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

            for (int i = 0; i < inputPeople; i++)
            {
                string[] people = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

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

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

                    citizens.Add(citizen);
                }
                else if (people.Length == 3)
                {
                    string name  = people[0];
                    int    age   = int.Parse(people[1]);
                    string group = people[2];

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

                    rebels.Add(rebel);
                }
            }

            string input = string.Empty;

            int tottalFood = 0;

            while ((input = Console.ReadLine()) != "End")
            {
                foreach (var person in citizens)
                {
                    if (person.Name == input)
                    {
                        person.BuyFood();

                        tottalFood += person.Food;
                    }
                }

                foreach (var rebel in rebels)
                {
                    if (rebel.Name == input)
                    {
                        rebel.BuyFood();

                        tottalFood += rebel.Food;
                    }
                }
            }

            Console.WriteLine(tottalFood);
        }