示例#1
0
        private static Dictionary <int, SueData> LoadData(string path)
        {
            var sues = new Dictionary <int, SueData>();

            // Open the file to read from.
            using (StreamReader sr = File.OpenText(path))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    var nameSplit = s.Split(':');
                    var sueNumber = int.Parse(nameSplit[0].Split(' ')[1]);

                    var list      = s.Substring(nameSplit[0].Length + 2);
                    var listSplit = list.Split(',');

                    var newSue = new SueData();

                    foreach (var item in listSplit)
                    {
                        string itemName  = item.Split(':')[0].Trim(' ');
                        int    itemValue = int.Parse(item.Split(':')[1]);

                        Type         type = newSue.GetType();
                        PropertyInfo prop = type.GetProperty(itemName);
                        prop.SetValue(newSue, itemValue, null);
                    }

                    sues[sueNumber] = newSue;
                }
            }

            return(sues);
        }
示例#2
0
        static void Main(string[] args)
        {
            var aunts = LoadData("input.txt");

            var masterData = new SueData
            {
                children    = 3,
                cats        = 7,
                samoyeds    = 2,
                pomeranians = 3,
                akitas      = 0,
                vizslas     = 0,
                goldfish    = 5,
                trees       = 3,
                cars        = 2,
                perfumes    = 1,
            };

            foreach (var aunt in aunts)
            {
                if (masterData.compare(aunt.Value))
                {
                    Console.WriteLine($"I found the aunt, it's number {aunt.Key}");
                }
            }

            Console.ReadKey();
        }
示例#3
0
        public bool compare(SueData comp)
        {
            if (comp.children != -1 && comp.children != children)
            {
                return(false);
            }

            if (comp.cats != -1 && comp.cats <= cats)
            {
                return(false);
            }

            if (comp.samoyeds != -1 && comp.samoyeds != samoyeds)
            {
                return(false);
            }

            if (comp.pomeranians != -1 && comp.pomeranians <= pomeranians)
            {
                return(false);
            }

            if (comp.akitas != -1 && comp.akitas != akitas)
            {
                return(false);
            }

            if (comp.vizslas != -1 && comp.vizslas != vizslas)
            {
                return(false);
            }

            if (comp.goldfish != -1 && comp.goldfish >= goldfish)
            {
                return(false);
            }

            if (comp.trees != -1 && comp.trees <= trees)
            {
                return(false);
            }

            if (comp.cars != -1 && comp.cars != cars)
            {
                return(false);
            }

            if (comp.perfumes != -1 && comp.perfumes != perfumes)
            {
                return(false);
            }
            return(true);
        }