コード例 #1
0
ファイル: Program.cs プロジェクト: vv-b-s/SoftUni
        static void Main(string[] args)
        {
            var cats = new Dictionary <string, Cat>();

            var input = "";

            while ((input = Console.ReadLine()) != "End")
            {
                var data    = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                var catType = data[0];
                var catName = data[1];

                if (catType == "Siamese")
                {
                    cats[catName] = new SiameseCat(catName, earSize: long.Parse(data[2]));
                }

                else if (catType == "Cymric")
                {
                    cats[catName] = new CymricCat(catName, furLength: double.Parse(data[2]));
                }

                else if (catType == "StreetExtraordinaire")
                {
                    cats[catName] = new StreetExtraordinaireCat(catName, decibelsOfMeowing: long.Parse(data[2]));
                }
            }

            var catToLookFor = Console.ReadLine();

            Console.WriteLine(cats[catToLookFor]);
        }
コード例 #2
0
    public static void Main()
    {
        var cats = new Dictionary <string, Cat>();

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            var split = input.Split();

            string type = split[0];
            string name = split[1];
            string data = split[2];

            if (type == "Siamese")
            {
                cats[name] = new SiameseCat(name, int.Parse(data));
            }
            else if (type == "Cymric")
            {
                cats[name] = new CymricCat(name, double.Parse(data));
            }
            else if (type == "StreetExtraordinaire")
            {
                cats[name] = new StreetExtraordinaireCat(name, int.Parse(data));
            }
        }

        string nameToPrint = Console.ReadLine();

        Console.WriteLine(cats[nameToPrint]);
    }
コード例 #3
0
        static void Main()
        {
            string line;

            List <Cat> cats = new List <Cat>();

            while ((line = Console.ReadLine()) != "End")
            {
                var info = line.Split();
                var type = info[0];
                var name = info[1];
                Cat cat  = new Cat();

                switch (type)
                {
                case "Siamese":
                    var earSize = double.Parse(info[2]);
                    cat = new SiameseCat(name, earSize);
                    break;

                case "Cymric":
                    var furLength = double.Parse(info[2]);
                    cat = new CymricCat(name, furLength);
                    break;

                case "StreetExtraordinaire":
                    var decibelOfMeows = double.Parse(info[2]);
                    cat = new StreetExtraordinaireCat(name, decibelOfMeows);
                    break;
                }

                cats.Add(cat);
            }

            var nameToPrint = Console.ReadLine();
            Cat catToPrint  = cats.First(c => c.Name == nameToPrint);

            Console.WriteLine(catToPrint);
        }