Example #1
0
        public void Run(string[] args)
        {
            IReader reader;

            if (args.Length > 0)
            {
                reader = new FileReader(args[0]);
            }
            else
            {
                reader = new ConsoleReader();
            }

            string salt      = ReadLine();
            int    keyToFind = int.Parse(ReadLine());

            Solve(salt, keyToFind);
        }
Example #2
0
        public void Run(string[] args)
        {
            IReader reader;

            if (args.Length > 0)
            {
                reader = new FileReader(args[0]);
            }
            else
            {
                reader = new ConsoleReader();
            }

            List <RainDeer> raindeers = new List <RainDeer>();
            //int time = int.Parse(reader.ReadLine());
            int time = 2503;

            while (!reader.EndOfStream)
            {
                var input = reader.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    break;
                }

                var split = input.Split(' ');
                var deer  = new RainDeer()
                {
                    Name     = split[0],
                    Speed    = int.Parse(split[3]),
                    RaceTime = int.Parse(split[6]),
                    RestTime = int.Parse(split[13])
                };

                raindeers.Add(deer);
            }

            for (int i = 0; i < time; i++)
            {
                foreach (var deer in raindeers)
                {
                    if (deer.Statistics.CurrentRaceTime >= deer.RaceTime)
                    {
                        deer.Statistics.CurrentRestTime++;
                        if (deer.Statistics.CurrentRestTime >= deer.RestTime)
                        {
                            deer.Statistics.CurrentRaceTime = 0;
                            deer.Statistics.CurrentRestTime = 0;
                        }
                    }
                    else
                    {
                        deer.Statistics.CurrentRaceTime++;
                        deer.Statistics.TotalDistance += deer.Speed;
                    }
                }

                var ordered = raindeers.OrderByDescending(x => x.Statistics.TotalDistance);
                var max     = ordered.First().Statistics.TotalDistance;

                foreach (var deer in ordered)
                {
                    if (deer.Statistics.TotalDistance == max)
                    {
                        deer.Statistics.Score++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            var raceResult = raindeers.OrderByDescending(x => x.Statistics.Score);

            foreach (var deer in raceResult)
            {
                WriteLine($"{deer.Name} scored {deer.Statistics.Score}.");
            }
        }