コード例 #1
0
        static void Main(string[] args)
        {
            List <string> inputStrings = new List <string>();

            if (args.Count() < 1)
            {
                inputStrings.Add("../../inputs/input 1.txt");
                inputStrings.Add("../../inputs/input 2.txt");
                inputStrings.Add("../../inputs/input 3.txt");
            }
            else
            {
                for (int i = 0; i < args.Count(); i++)
                {
                    inputStrings.Add(args[i]);
                }
            }

            foreach (string inputString in inputStrings)
            {
                Dictionary <string, Parkers> customers = new Dictionary <string, Parkers>();

                string s;
                System.IO.StreamReader f = GetInputFile(inputString);
                while (f != null && (s = f.ReadLine()) != null)
                {
                    Parkers p = new Parkers(s);
                    if (customers.ContainsKey(p.plate))
                    {
                        if (customers[p.plate].CanPark(p.lastParked))
                        {
                            customers[p.plate].Merge(p);
                        }
                    }
                    else
                    {
                        customers.Add(p.plate, p);
                    }
                }
                foreach (string pl in customers.Keys)
                {
                    Parkers  p        = customers[pl];
                    DateTime nextPark = p.lastViolation.AddMonths(6);
                    Console.WriteLine(p.vType + " " + p.plate + " " +
                                      (!p.CanPark(DateTime.Now) ? "T " : "F ") + p.lastParked.Year + "-" + p.lastParked.Month.ToString("D2") + "-" + p.lastParked.Day.ToString("D2") + " " +
                                      p.totalFines.ToString() + " " +
                                      (p.CanPark(DateTime.Now) ? "" : nextPark.Year + "-" + nextPark.Month.ToString("D2") + "-" + nextPark.Day.ToString("D2") + " ")

                                      );
                }

                Console.WriteLine("");
                Console.WriteLine("");
            }
        }
コード例 #2
0
 public void Merge(Parkers p)
 {
     foreach (DateTime v in p.violations.Keys)
     {
         violations.Add(v, v);
     }
     totalFines += p.totalFines;
     if (p.lastParked > lastParked)
     {
         lastParked = p.lastParked;
     }
 }