Exemplo n.º 1
0
        static void Main(string[] args)
        {
            VacationSchedule aliceSchedule = new VacationSchedule();
            VacationSchedule bobSchedule   = new VacationSchedule();

            int readingPointer = 0;

            string[] input = System.IO.File.ReadAllLines(@"in.txt");

            int daysOfForecast        = Int32.Parse(input[0]);
            int numberOfAliceVacation = Int32.Parse(input[1]);

            for (int aliceVacationIndex = 2; aliceVacationIndex < numberOfAliceVacation + 2; aliceVacationIndex++)
            {
                DayDuration currentAliceVacation = new DayDuration();
                string[]    vacationInput        = input[aliceVacationIndex].Split(';');
                aliceSchedule.AddVacation(new DayDuration(Int32.Parse(vacationInput[0]), Int32.Parse(vacationInput[1])));
                readingPointer = aliceVacationIndex;
            }

            int numberOfBobVacation = Int32.Parse(input[readingPointer]);

            for (int bobVacationIndex = readingPointer + 1; bobVacationIndex < readingPointer + numberOfBobVacation + 1; bobVacationIndex++)
            {
                DayDuration currentAliceVacation = new DayDuration();
                string[]    vacationInput        = input[bobVacationIndex].Split(';');
                bobSchedule.AddVacation(new DayDuration(Int32.Parse(vacationInput[0]), Int32.Parse(vacationInput[1])));
            }

            ForecastResult forecastResult = SafeDaysCalculator.Calculate(aliceSchedule, bobSchedule, numberOfBobVacation);

            System.IO.File.WriteAllText(@"out.txt", forecastResult.ToString());
            Console.ReadLine();
        }
Exemplo n.º 2
0
        public static ForecastResult Calculate(VacationSchedule admin1Vacations, VacationSchedule admin2Vacations, int daysOfForecast)
        {
            List <DayDuration> safeInterval   = new List <DayDuration>();
            List <DayDuration> unsafeInterval = new List <DayDuration>();

            int         currentSafeLevel = GetSafetyLevelOfDay(admin1Vacations, admin2Vacations, 1);
            DayDuration checkingInterval = new DayDuration(1, 1);

            if (currentSafeLevel == 0)
            {
                unsafeInterval.Add(checkingInterval);
            }
            else if (currentSafeLevel == 2)
            {
                safeInterval.Add(checkingInterval);
            }

            for (int checkingDay = 2; checkingDay <= daysOfForecast; checkingDay++)
            {
                int todaySafeLevel = GetSafetyLevelOfDay(admin1Vacations, admin2Vacations, checkingDay);

                if (todaySafeLevel == currentSafeLevel)
                {
                    checkingInterval.EndDay = checkingDay;
                }
                else
                {
                    checkingInterval = new DayDuration(checkingDay, checkingDay);

                    if (todaySafeLevel == 0)
                    {
                        unsafeInterval.Add(checkingInterval);
                    }
                    else if (todaySafeLevel == 2)
                    {
                        safeInterval.Add(checkingInterval);
                    }
                }

                currentSafeLevel = todaySafeLevel;
            }


            return(new ForecastResult(safeInterval, unsafeInterval));
        }
Exemplo n.º 3
0
 public void AddVacation(DayDuration vacation)
 {
     schedule.Add(vacation);
 }