public void CheckForPalindrome() { bool isPalindrome = StringProblem.IsPalindrome("ababababaYZababababa"); }
static void Main(string[] args) { int[] arr = new int[] { 1, 1, 2 }; int res = ArrayProblem.Duplicate1(ref arr); MyWrite(arr); string s = "loveleetcode"; Console.WriteLine(StringProblem.FirstUniqChar(s)); Console.ReadKey(); int oriInt = 123; Console.WriteLine(StringProblem.RevertInt(oriInt)); Console.ReadKey(); var revert = StringProblem.RevertString("hi, i am lucy."); Console.WriteLine(revert); Console.Read(); var resArr = ArrayProblem.TwoSum(new int[] { 2, 7, 11, 15 }, 18); MyWrite(resArr); //int[] arr = new int[] { 1, 1, 2 }; //int res = ArrayProblem.Duplicate(ref arr); //for(int i = 0; i < res; ++i) //{ // Console.WriteLine(arr[i]); //} Console.ReadKey(); Console.WriteLine("斐波拉契数列,第10位"); Console.WriteLine(Fibonacci.GetSeq(10)); //Console.ReadKey(); CStack.Output(); CArray.Output(); Console.WriteLine("....................."); ScoreArray sa = new ScoreArray(); sa.scores = new int[] { 99, 89, 88, 78, 55 }; Console.WriteLine("数组: [99, 89, 88, 78, 55]"); Console.WriteLine("avg: {0}", sa.GetAvg()); Console.WriteLine("max: {0}", sa.GetMax()); Console.WriteLine("min: {0}", sa.GetMin()); Console.WriteLine("....................."); Console.WriteLine("数组:[1, 3, 4, 6, 9]"); int[] sales = new int[] { 1, 3, 4, 6, 9 }; Console.WriteLine("和: {0}", Common.GetTotalCase(sales)); Console.WriteLine("....................."); Console.WriteLine("数组:[5, 1, 22, 7,9]"); double[] a = new double[] { 5, 1, 22, 7, 9 }; Console.WriteLine("中间数: {0}", Common.Middle(a)); Console.WriteLine("....................."); Console.WriteLine("Fibonacci sequence"); foreach (long fib in FibonacciGenerator.GetSequence(11)) { Console.WriteLine(fib); } Console.WriteLine("....................."); Console.WriteLine("斐波拉契数列第10位: {0}", Fibonacci.GetSequence(10)); Console.WriteLine("....................."); FactoryDemo(); Console.ReadKey(); }
public void OneTimeSetup() { _stringProblem = new StringProblem(); }
public static void Main(string[] args) { bool run = true; string target = "Default target"; bool useCache = false; int generations = 1000; int populationSize = 100; int selectionSize = 10; int mutationSize = 10; while (run) { Console.WriteLine ("Input target string for evolution ( " + target + " ):" ); string newTarget = Console.ReadLine (); if (newTarget != "") target = newTarget; StringProblem<StringIndividual> problem = new StringProblem<StringIndividual> (target); Console.WriteLine("Use caching in problem set ( " + useCache + " ) ?"); string newUseCache = Console.ReadLine (); if (newUseCache != "") useCache = readYNstring (newUseCache); ProblemSet<StringIndividual> tester = new ProblemSet<StringIndividual> (problem, useCache); Console.WriteLine ("Input generations amount ( " + generations + " ):"); string newGenerations = Console.ReadLine (); if (newGenerations != "") generations = Convert.ToInt32 (newGenerations); Console.WriteLine ("Input population size ( " + populationSize + " ):"); string newPopulationSize = Console.ReadLine (); if (newPopulationSize != "") populationSize = Convert.ToInt32 (newPopulationSize); Console.WriteLine ("Input selection size ( " + selectionSize + " ): "); string newSelectionSize = Console.ReadLine (); if (newSelectionSize != "") selectionSize = Convert.ToInt32 (newSelectionSize); Console.WriteLine ("Input mutation size ( " + mutationSize + " ): "); string newMutationSize = Console.ReadLine (); if (newMutationSize != "") mutationSize = Convert.ToInt32 (newMutationSize); Genetic.Evolution<StringIndividual> evolution = new Evolution<StringIndividual> (generations, populationSize, selectionSize, mutationSize, tester, true); Console.WriteLine ("Evolution result: " + evolution.win ().ToString ()); Console.WriteLine ("Do you want to run again (Y/N)?"); string runAgain = Console.ReadLine (); run = readYNstring(runAgain); } }