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()); } }
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); } }
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 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); } }