public static void Main()
        {
            int[] arr = new int[2]{1,2};
            int[] arr1 = new int[2]{2,2};
            int[] arr2 = new int[2]{3,2};
            int[] arr3 = new int[2]{4,2};

            Point first = new Point(arr);
            Point second = new Point(arr1);
            Point third = new Point(arr2);
            Point forth = new Point(arr3);
            List<Rectangle> lists = new List<Rectangle>(){
                new Rectangle(first, 11,2),
                new Rectangle(second, 3,2),
                new Rectangle(third, 4,2),
                new Rectangle(forth, 4,4)
            };
            Console.WriteLine(first);
            Console.WriteLine(second);
            Console.WriteLine(third);
            Console.WriteLine(forth);

            Console.WriteLine("Sort by Area: ");
            var sortListByArea = Rectangle.Sort(lists, Rectangle.Area);
            foreach(var item in sortListByArea){
                Console.WriteLine(item);
            }

            Console.WriteLine("Sort by Diagonal: ");
            var sortListByDiagonal = Rectangle.Sort(lists, Rectangle.Diagonal);
            foreach (var item in sortListByDiagonal)
            {
                Console.WriteLine(item);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            List<IShape> shapes = new List<IShape>();
            shapes.Add(new Rectangle(20, 3));
            shapes.Add(new Circle(5));
            shapes.Add(new Rhombus(3, 4, 1));
            foreach (var shape in shapes)
            {
                Console.WriteLine(shape.GetType().Name);
                Console.WriteLine( shape.CalculateArea());
                Console.WriteLine(shape.CalculatePerimeter());

            }
        }
Пример #3
0
        public static void Main()
        {
            List<Student> students = new List<Student>();
            students.Add(new Student("Chiflik", "Isterov", "5869898"));
            students.Add(new Student("Minka", "Petrova", "8789755"));
            students.Add(new Student("Sashka", "Ribarova", "1251125"));
            students.Add(new Student("Boiko", "Filipov", "54687563"));
            students.Add(new Student("Cvetan", "Gospodinov", "1234456"));
            students.Add(new Student("Dimitar", "Ganchev", "6668755"));
            students.Add(new Student("Alexander", "Dimitrov", "2222222"));
            students.Add(new Student("Dobrinka", "Ivankova", "552552"));
            students.Add(new Student("Geograf", "Vasilev", "52522"));
            students.Add(new Student("Penka", "Lopatkova", "3332212"));

            foreach (var student in students.OrderBy(student => student.FacultyNumber))
            {
                Console.WriteLine("{0}{1} - Faculty number: {2}", student.FirstName, student.SecondName, student.FacultyNumber);
            }
            Console.WriteLine();

            List<Worker> workers = new List<Worker>();
            workers.Add(new Worker("Chiflik", "Isterov", 500, 8));
            workers.Add(new Worker("Minka", "Petrova", 200, 4));
            workers.Add(new Worker("Marmar", "Vylov", 500, 6));
            workers.Add(new Worker("Petar", "Yanov", 550, 8));
            workers.Add(new Worker("Yonko", "Narov", 650, 7));
            workers.Add(new Worker("Milica", "Dimitrova", 250, 2));
            workers.Add(new Worker("Ognqn", "Serafimov", 850, 8));
            workers.Add(new Worker("Evelina", "Dimitrova", 1050, 10));
            workers.Add(new Worker("Kristina", "Kirilova", 1250, 16));
            workers.Add(new Worker("Korleone", "With Al Kapone", 300, 8));

            foreach (var worker in workers.OrderByDescending(worker => worker.MoneyPerHour()))
            {
                Console.WriteLine("{0} {1} - Money per hour: {2:f2}", worker.FirstName, worker.SecondName, worker.MoneyPerHour());
            }
            Console.WriteLine();

            List<Human> studentsAndWorkers = new List<Human>();
            studentsAndWorkers.AddRange(students);
            studentsAndWorkers.AddRange(workers);

            foreach (var studentOrWorker in studentsAndWorkers.OrderBy(h => h.FirstName).ThenBy(h => h.SecondName))
            {
                Console.WriteLine("{0} {1}", studentOrWorker.FirstName, studentOrWorker.SecondName);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            List<Student> students = new List<Student>()
            {
                new Student("Angel","Angelov","12343"),
                new Student("Bojidar","Bratoev","432d213"),
                new Student("Cikoriq","Ciklamena","hd732j"),
                new Student("Dobra","Dudeva","9189819"),
                new Student("Elen","Elenov","72j21"),
                new Student("Fred","Flinstone","3fjjf2"),
                new Student("Gergana","Grudeva","8932929"),
                new Student("Haralambii","Hristov","r8w0q"),
                new Student("Iliq","Iliev","erdew"),
                new Student("Jecho","Jechev","73h371")
            };
            List<Worker> workers = new List<Worker>()
            {
                new Worker("Anton","Antonov",100,2),
            new Worker("Borko","Biserov",300,8),
            new Worker("Cveta","Cimilova",200,4),
            new Worker("Duda","DObreva",600,4),
            new Worker("Emiliq","Encheva",120, 2),
            new Worker("Fani","Filipova",130,8),
            new Worker("Grigorii","Georgoev",200,8),
            new Worker("Hristo","Hristov",246,8),
            new Worker("Ivan","Ivanov",250,8),
            new Worker("Jelqzko","Jelev",200,8)
            };
            Console.WriteLine("###Students###");

            students.OrderBy(st => st.StudentNumber).ToList().ForEach(st => Console.WriteLine("{0} -stud number-> {1}", st.FistName, st.StudentNumber));
            Console.WriteLine("###Workers###");

            workers.OrderByDescending(wr => wr.MoneyPerHour()).ToList().ForEach(wr => Console.WriteLine("{0} -money per hour->{1}", wr.FistName, wr.MoneyPerHour()));

            List<Human> humans = new List<Human>();
            humans.AddRange(workers);
            humans.AddRange(students);
            Console.WriteLine("###Humans###");
            humans
                .OrderBy(h => h.FistName)
                .ThenBy(h => h.LastName)
                .ToList()
                .ForEach(h => Console.WriteLine("{0} {1}", h.FistName, h.LastName));
        }
 public override void UpdateRacers(float deltaTimeS, List<Racer> racers)
 {
     int numRacer = racers.Count;
     deltaTimeS *= 1000.0f;
     for (int racerIndex1 = 0; racerIndex1 < numRacer; racerIndex1++)
     {
         Racer racerA = racers[racerIndex1];
         // Updates the racers that are alive
         if (racerA.IsAlive())
         {
             //Racer update takes milliseconds
             racerA.update(deltaTimeS);
             for (int racerIndex2 = 0; racerIndex2 < numRacer; racerIndex2++)
             {
                 
                 if (racerIndex1 != racerIndex2)
                 {
                     Racer racerB = racers[racerIndex2];
                     // Collides
                     if (racerA.IsCollidable() && racerB.IsCollidable() && racerA.CollidesWith(racerB))
                     {
                         OnRacerExplodes(racerA);
                         // Get rid of all the exploded racers
                         racers.RemoveAt(racerIndex1);
                         racerIndex1--;
                         numRacer--;
                         break;
                         //
                     }
                 }
                 
             }
         }
         else
         {
             racerA.Destroy();
             racers.RemoveAt(racerIndex1);
             racerIndex1--;
             numRacer--;
         }
     }
 }
Пример #6
0
 public Method1(ReportTableRowList dataList1, ReportTableRowList dataList2, ReportTableRowList dataList3, TimeSpan time)
 {
     InitializeComponent();
     _eventList = new List<ReportTableRowList> {dataList1, dataList2, dataList3};
     _time = time;
 }
Пример #7
0
 public School(string name, List<Class> classes)
 {
     this.Name = name;
     this.Classes = classes;
 }
        public virtual void UpdateRacers(float deltaTimeS, List<Racer> racers)
        {

        }
        static void Main()
        {
            //string line1 = "<?php";
            //string line2 = "$browser = $_SERVER['HTTP_USER_AGENT']  ;";
            //string line3 = "$arr =  array();";
            //string line4 = "$arr[$zero]   = $browser;";
            //string line5 = " var_dump($arr);";
            //string line6 = "?>";
            //string[] arr = new string[] { line1, line2, line3, line4, line5, line6 };

            string input = Console.ReadLine();
            List<string> lines = new List<string>();
            while (input != "?>")
            {
                lines.Add(input);
                input = Console.ReadLine();
            }
            lines.Add(input);
            string[] arr = lines.ToArray();
            List<string> listNames = new List<string>();
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i].Length != 0)
                {
                    if (arr[i].Substring(0, 1) != "#" && arr[i].Substring(0, 1) != "//" && arr[i].Substring(0, 1) != "/*")
                    {
                        int index = arr[i].IndexOf("$");
                        int temp = index;
                        while (index != -1)
                        {
                            index++;
                            string currChar = arr[i].Substring(index, 1);
                            string name = string.Empty;
                            while (currChar != " " && currChar != "[" && currChar != "]" && currChar != ";" && currChar != ")" && currChar != "=" && currChar != "'" && currChar != "\"")
                            {
                                name += currChar;
                                index++;
                                currChar = arr[i].Substring(index, 1);
                            }
                            bool addState = true;
                            foreach (string ele in listNames)
                            {
                                if (name == ele)
                                {
                                    addState = false;
                                }
                            }
                            if (addState)
                            {
                                listNames.Add(name);
                            }
                            index = arr[i].IndexOf("$");
                            arr[i] = arr[i].Remove(index, 1);
                            index = arr[i].IndexOf("$");
                        }
                    }
                }
            }
            listNames.Sort();
            Console.WriteLine("{0}", listNames.Count);
            foreach (string name in listNames)
            {
                Console.WriteLine(name);
            }
        }
        static void Main()
        {
            StringBuilder input = new StringBuilder();
            string inputLine = Console.ReadLine();
            while (inputLine != "?>")
            {
                input.Append("\n");
                input.Append(inputLine);
                inputLine = Console.ReadLine();
            }
            //string thePHPCode = "<?php $browser = $_SERVER['HTTP_USER_AGENT']    ; $arr = array(); $arr[$zero]    = $browser;    var_dump($arr);  ?>";
            //string thePHPCode = "<?php /* This is $var1 in comments */ \n $var3 = \"Some string \\$var4 with var escaped. \"; \n echo $var5; echo(\"$foo,$bar\"); \n // Another comment with variable $var2";
            //string thePHPCode = "<?php \n # this is $comment \n $valid_var='\"text\"'...{$valid_var}'; \n $just=\"Just another var $Just...\";$just=$code;\n?>";
            string thePHPCode = input.ToString();
            bool isVar = false;
            bool inComment = false;
            bool escaped = false;
            bool inString1 = false;
            bool inString2 = false;
            StringBuilder varPHP = new StringBuilder();
            List<string> allVars = new List<string>();
            foreach (char symbol in thePHPCode)
            {
                //comments
                if (symbol == '#' || symbol == '/')
                {
                    inComment = true;
                    continue;
                }
                if (inComment == true)
                {
                    if (symbol == '\n' || symbol == '/')
                    {
                        inComment = false;
                        continue;
                    }

                }
                //strings
                if (symbol == '"' && inString1 != true)
                {
                    inString1 = true;
                    continue;
                }
                if (inString1 == true)
                {
                    if (symbol == '\\')
                    {
                        escaped = true;
                    }
                    if (escaped == true && symbol == ' ')
                    {
                        escaped = false;
                        //what if we have an escaped var, and after that a non-escaped var?
                    }
                    if (symbol == '"')
                    {
                        inString1 = false;
                        escaped = false;
                        continue;
                    }
                }
                //other strings
                if (symbol == '\'' && inString2 != true)
                {
                    inString2 = true;
                    continue;
                }
                if (inString2 == true)
                {
                    if (symbol == '\\')
                    {
                        escaped = true;
                    }
                    if (escaped == true && symbol == ' ')
                    {
                        escaped = false;
                        //what if we have an escaped var, and after that a non-escaped var?
                    }
                    if (symbol == '\'')
                    {
                        inString2 = false;
                        escaped = false;
                        continue;
                    }
                }
                //vars
                if (symbol == '$' && inComment != true && escaped != true)
                {
                    isVar = true;
                    continue;
                }
                if (isVar == true)
                {
                    if (symbol != ' ' && symbol != '=' && symbol != '[' && symbol != ']' && symbol != '(' && symbol != ')' && symbol != '{' && symbol != '}' && symbol != ';' && symbol != ',' && symbol != '"' && symbol != '\'' && symbol != '\'' && symbol != '.')
                    {
                        varPHP.Append(symbol);
                    }
                    else
                    {
                        bool contains = allVars.Contains(varPHP.ToString());
                        if (contains == false)
                        {
                            allVars.Add(varPHP.ToString());
                        }
                        varPHP.Clear();
                        isVar = false;
                    }

                }
            }
            Console.WriteLine(allVars.Count);
            allVars.Sort();
            for (int i = 0; i < allVars.Count; i++)
            {
                Console.WriteLine(allVars[i]);
            }
        }
 public static IEnumerable<Rectangle> Sort(List<Rectangle> list, Cmp compare)
 {
     var sortList = list
         .OrderBy(x => compare(x));
     return sortList;
 }
Пример #12
0
 public Method2(ReportTableRowList data)
 {
     InitializeComponent();
     _eventList = new List<ReportTableRowList> {data};
 }
        public override void UpdateRacers(float deltaTimeS, List<Racer> racers)
        {
            List<Racer> racersNeedingRemoved = new List<Racer>();
            racersNeedingRemoved.Clear();

            // Updates the racers that are alive
            int racerIndex = 0;
            for (racerIndex = 1; racerIndex <= 1000; racerIndex++)
            {
                if (racerIndex <= racers.Count)
                {
                    if (racers[racerIndex - 1].IsAlive())
                    {
                        //Racer update takes milliseconds
                        racers[racerIndex - 1].update(deltaTimeS * 1000.0f);
                    }
                }
            }
            // Collides
            for (int racerIndex1 = 0; racerIndex1 < racers.Count; racerIndex1++)
            {
                for (int racerIndex2 = 0; racerIndex2 < racers.Count; racerIndex2++)
                {
                    Racer racer1 = racers[racerIndex1];
                    Racer racer2 = racers[racerIndex2];
                    if (racerIndex1 != racerIndex2)
                    {
                        if (racer1.IsCollidable() && racer2.IsCollidable() && racer1.CollidesWith(racer2))
                        {
                            OnRacerExplodes(racer1);
                            racersNeedingRemoved.Add(racer1);
                            racersNeedingRemoved.Add(racer2);
                        }
                    }
                }
            }
            // Gets the racers that are still alive
            List<Racer> newRacerList = new List<Racer>();
            for (racerIndex = 0; racerIndex != racers.Count; racerIndex++)
            {
                // check if this racer must be removed
                if (racersNeedingRemoved.IndexOf(racers[racerIndex]) < 0)
                {
                    newRacerList.Add(racers[racerIndex]);
                }
            }
            // Get rid of all the exploded racers
            for (racerIndex = 0; racerIndex != racersNeedingRemoved.Count; racerIndex++)
            {
                int foundRacerIndex = racers.IndexOf(racersNeedingRemoved[racerIndex]);
                if (foundRacerIndex >= 0) // Check we've not removed this already!
                {
                    racersNeedingRemoved[racerIndex].Destroy();
                    racers.Remove(racersNeedingRemoved[racerIndex]);
                }
            }
            // Builds the list of remaining racers
            racers.Clear();
            for (racerIndex = 0; racerIndex < newRacerList.Count; racerIndex++)
            {
                racers.Add(newRacerList[racerIndex]);
            }

            for (racerIndex = 0; racerIndex < newRacerList.Count; racerIndex++)
            {
                newRacerList.RemoveAt(0);
            }
        }