示例#1
0
 public Spot(int x, int y, ParkZone parkZone)
 {
     X        = x;
     Y        = y;
     ParkZone = parkZone;
     ParkZone.AddFreeParkSpot(this);
     CalcDistToTarget();
     CalcTimeToTarget();
     CalculatePriceForStay();
 }
示例#2
0
        private static void ReadInput()
        {
            var numOfParkZones = int.Parse(Console.ReadLine());

            parkZones = new List <ParkZone>();
            var parkZoneParams = new List <string>();

            for (int i = 0; i < numOfParkZones; i++)
            {
                parkZoneParams.Add(Console.ReadLine());
            }

            var freeParkSpots = Console.ReadLine()
                                .Split(';')
                                .ToArray();

            var targetCoord = Console.ReadLine()
                              .Split(", ".ToArray(), StringSplitOptions.RemoveEmptyEntries)
                              .Select(int.Parse)
                              .ToArray();

            var target      = new Spot(targetCoord[0], targetCoord[1]);
            var timePerSpot = int.Parse(Console.ReadLine());

            for (int i = 0; i < parkZoneParams.Count; i++)
            {
                var line = parkZoneParams[i].Split(':').ToArray();

                var parkZoneName = line[0].Trim();

                var parameters = line[1]
                                 .Trim()
                                 .Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();

                var coordinates = parameters.Take(4).Select(int.Parse).ToArray();
                var price       = decimal.Parse(parameters[4]);
                var parkZone    = new ParkZone(parkZoneName, coordinates[0], coordinates[1], coordinates[2],
                                               coordinates[3], price, target, timePerSpot);
                parkZones.Add(parkZone);
            }

            foreach (var parkSpotStr in freeParkSpots)
            {
                var parkSpotCoord = parkSpotStr
                                    .Split(", ".ToArray(), StringSplitOptions.RemoveEmptyEntries)
                                    .Select(int.Parse)
                                    .ToArray();

                var x = parkSpotCoord[0];
                var y = parkSpotCoord[1];
                foreach (var parkZone in parkZones)
                {
                    if (parkZone.isInParkZone(x, y))
                    {
                        var parkSpot = new Spot(x, y, parkZone);
                        break;
                    }
                }
            }
        }