Пример #1
0
        public JobsDone Work(Dictionary <string, List <int> > Jobs)
        {
            JobsDone jobsDone = new JobsDone();

            foreach (var Vehicle in Vehicles)
            {
                int maxCounter = 0;
                int index      = 0;
                for (int i = 0; i < Vehicle.JobTypeCounter; i++)
                {
                    if (maxCounter < Jobs[Vehicle.JobTypeList[i]].Count)
                    {
                        maxCounter = Jobs[Vehicle.JobTypeList[i]].Count;
                        index      = i;
                    }
                }
                if (maxCounter == 0)
                {
                    //todo nincs munka a kocsira
                }
                else
                {
                    //todo van munka a kocsira tegyük le, countereket manageljük
                    jobsDone.VehicleJobList.Add(Vehicle.ID, Jobs[Vehicle.JobTypeList[index]][0]);
                    Jobs[Vehicle.JobTypeList[index]].RemoveAt(0);
                }
            }
            return(jobsDone);
        }
Пример #2
0
        static void Main()
        {
            FreeVehicle freeVehicle = new FreeVehicle();
            Dictionary <string, List <int> > Jobs = new Dictionary <string, List <int> >();

            using (FileStream fs = new FileStream(Directory.GetCurrentDirectory() + @"\Iinput.txt", FileMode.Open, FileAccess.Read))
            {
                try
                {
                    StreamReader sr       = new StreamReader(fs);
                    int          Vehicles = int.Parse(sr.ReadLine());
                    for (int i = 0; i < Vehicles; i++)
                    {
                        freeVehicle.Add(sr.ReadLine());
                    }
                    int JobsCounter = int.Parse(sr.ReadLine());
                    for (int i = 0; i < JobsCounter; i++)
                    {
                        Job job = new Job(sr.ReadLine());
                        if (Jobs.ContainsKey(job.JobType))
                        {
                            Jobs[job.JobType].Add(job.ID);
                        }
                        else
                        {
                            Jobs.Add(job.JobType, new List <int>()
                            {
                                job.ID
                            });
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("File error:");
                    Console.WriteLine(e.Message);
                    throw (e);
                }
            }
            freeVehicle.Sort();

            JobsDone Out = freeVehicle.Work(Jobs);

            StringBuilder stringBuilder = new StringBuilder();

            foreach (var item in Out.VehicleJobList)
            {
                stringBuilder.AppendLine(item.Key.ToString() + ' ' + item.Value.ToString());
            }
            try
            {
                File.WriteAllText(Directory.GetCurrentDirectory() + @"\Output.txt", stringBuilder.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }