コード例 #1
0
        public override void Start()
        {
            const string T = "用于调试字符串,字符串。";

            Logger.Info("子字符串");

            Logger.Write(Str.Remove(T, 2, 1));
            Logger.Write(Str.RemoveEnd(T, 2));
            Logger.Write(Str.RemoveStart(T, 2));
            Logger.Write(Str.RemoveBefore(T, '调'));
            Logger.Write(Str.RemoveAfter(T, '调'));

            Logger.Write(Str.Substring(T, 1));
            Logger.Write(Str.TrimToLength(T, 3, "..."));

            string T3 = "aa-asd-aa";

            Logger.Info("长度不变的处理");

            Logger.Write(T3 = Str.Capitalize(T3));
            Logger.Write(Str.UnCapitalize(T3));
            Logger.Write(T3 = Str.ToCamel(T3));
            Logger.Write(T3 = Str.ToPascal(T3));
            Logger.Write(T3 = Str.Hyphenate(T3));
            Logger.Write(Str.ToLength(T3, 10));
            Logger.Write(Str.ToLength(T3, 8));

            Logger.Info("字符性质");

            Logger.Write(Str.CLength(T));
            Logger.Write(Str.Count(T, '用'));
            Logger.Write(Str.Count("aaabbbaaaa", "aa"));

            Logger.Info("编码");

            Logger.Write(int.Parse("12fe", System.Globalization.NumberStyles.HexNumber));


            Logger.Write(Str.HtmlEncode("<br>sdasd<div>sdasd</div>"));

            Logger.Write(Str.HtmlToString("<br>sdasd<div>sdasd</div>"));

            Logger.Write(Str.HtmlNoScript("<script>ddd</script><div onclick='alert()' style='height:expression(alert());font-size:2' sa='ggg'></div>"));

            Logger.Write(Str.UnicodeDecode(Str.UnicodeEncode("不飞asdaa?=s", "%u"), "%u"));
            Logger.Write(Str.UrlEncode("不飞asdaa?=s"));
            Logger.Write(Str.Unescape(Str.Escape("不飞asdaa?=s ")));


            ArrayString s = new ArrayString("ss,ss,dasd,asd", ',');

            s.Add("asfdsf");
            s.RemoveAt(0);
            Logger.Write(s.Count);

            Logger.Write(s.Length);

            Logger.Write(s.ToString());
        }
コード例 #2
0
        public static List<StringHashFuncPerfModel> GetPerformanceOfStringHashingAlgos()
        {
            List<StringHashFuncPerfModel> ret = new List<StringHashFuncPerfModel>();
            List<string> englishWords = ResourceAccessor.GetEnglishWords();
            LinkedList<string>[] hashTable = new LinkedList<string>[Int32.MaxValue];
            foreach(string w in englishWords)
            {
                ArrayString w1 = new ArrayString(w);
                Int32 i = w1.GetHashCode();

            }

            return ret;
        }
コード例 #3
0
        public override void Start()
        {
            Logger.Start("数组字符串");


            ArrayString a = new ArrayString("hello,Py,world", ',');

            a.Add("ok");
            a.RemoveAt(0);

            Logger.Write("hello,Py,world  + ok  ->   {0}", a.ToString());

            a[2] = "1";

            Logger.Write("设置a[2]后 , 字符串为     {0}", a.ToString());
        }
コード例 #4
0
 private static string __fixArrayStr(string param, ArrayString method)
 {
     if (method == ArrayString.Init)
     {
         return("array:");
     }
     else if (method == ArrayString.Split)
     {
         return(";");
     }
     else if (method == ArrayString.End)
     {
         return(param.Replace("array:;", "array:"));
     }
     else if (method == ArrayString.Fix)
     {
         return(param.Replace("array:", ""));
     }
     return(default(string));
 }
コード例 #5
0
ファイル: CoreDemo.cs プロジェクト: tvrjcf/Demo
        /// <summary>
        /// 开始测试。
        /// </summary>
        public override void Start()
        {
            #region 准备

            Logger.Info("Core 是 库的重要部分, 提供了简化代码量的方法。");

            #endregion

            #region QC

            Logger.Info("QC 提供了常用转换函数");

            Logger.Write(QC.IP(QC.IP("127.158.0.0")));


            #endregion

            #region RegExp

            Logger.Info("正则表达式");

            Logger.Write(RegExp.Test("4", RegExp.Number));

            #endregion

            #region Check

            Logger.Info("Check  容纳了检查字符串的方法");

            Logger.Write(" Check.CheckRequestString(\"asdag\'g1=1\")  ->   {0}", Check.CheckRequestString("asdag'g1=1"));
            Logger.Write(" Check.IsIP(\"192.168.1.1\")  ->   {0}", Check.IsIP("192.168.1.1"));

            #endregion

            #region Str

            Logger.Info("字符串");

            DateTime dt = DateTime.Now.Add(new TimeSpan(4, 0, 0, -1));

            Logger.Write(Str.ToTimeString(dt));

            #endregion

            #region ArrayString

            Logger.Info("ArrayString 数组字符串");

            ArrayString s = new ArrayString("aaa,bbb,ccc", ',');

            Logger.Write(s[0]);

            s[1] = "bbbb";

            Logger.Write(s);

            s.Add("sss");

            Logger.Write(s);

            s.RemoveAt(1);

            Logger.Write(s);

            s.Clear();

            Logger.Write(s == "");

            s += "aaa,ddd,ccc";

            Logger.Write(s);

            s.Sort();

            Logger.Write(s);

            s -= "aaa";

            Logger.Write(s);

            s -= s;

            Logger.Write(s);

            Logger.Write(ArrayString.ReplaceValue("aaa,aaaaa,wqe,aaa,sfd,aaa", "aaa", "gg", ","));

            #endregion

            #region StringHelper

            Logger.Info("使用 StringHelper辅助字符串");

            StringHelper sh = new StringHelper();

            string input = @"用法 223, 三大殿,固定首发";

            sh.Pattern = @"用法{$N}, 三大殿,{$F}";


            sh.Match(input);


            foreach (string k in sh)
            {
                Logger.Write("{0}  ->    {1}", k, sh[k]);
            }

            #endregion
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: yuchijen/Algorithm
        static void Main(string[] args)
        {
            var asa = new ArrayString();


            //asa.FindAnagrams("cbaebabacd", "abc");
            //foreach (var x in asa.MajorityElement2(new int[5] { 2, 2, 2, 4, 4 }))
            //    Console.WriteLine(x);
            ////forwarding = [[1, 1000],[2, 7000],[3, 12000]], retrun = [[1, 10000],[2, 9000],[3, 3000],[4, 2000]]
            //var f = new List<List<int>>();
            //var r = new List<List<int>>();
            //f.Add(new List<int>() { 1, 1000 });
            //f.Add(new List<int>() { 2, 7000 });
            //f.Add(new List<int>() { 3, 12000 });
            //r.Add(new List<int>() { 1, 10000 });
            //r.Add(new List<int>() { 2, 9000 });
            //r.Add(new List<int>() { 3, 3000 });
            //r.Add(new List<int>() { 4, 2000 });

            //var cpair = asa.ClosestPair(f, r, 10000);
            //foreach(var x in cpair)
            //{
            //    foreach (var y in x)
            //        Console.Write(y+',');
            //    Console.WriteLine();
            //}


            var ast = new AsyncTest();

            ast.TestAsync();
            Console.WriteLine("doesn't block main thread");

            foreach (var x in asa.MajorityElement2(new int[5] {
                2, 2, 2, 4, 4
            }))
            {
                Console.WriteLine(x);
            }


            //var ast = new AsyncTest();
            //ast.TestAsync();

            //Console.WriteLine("Press any key to exit...");
            //Console.ReadLine();

            var C = new Circle();

            Console.WriteLine("circumference:" + C.Calculate((x) => { return(x * 2 * 3.14); }));

            UInt16 uii  = 0xFFFF;
            var    byt  = BitConverter.GetBytes(uii);
            Int32  data = BitConverter.ToInt16(byt, 0);

            Console.WriteLine(data);

            var bs = new BinarySearch();

            bs.MyPow(5.0, -4);

            var bm = new BitManipulate();

            bm.CountOneBit(4294967295);

            var bk = new BackTracking();

            Console.WriteLine("Permutation:########");
            var perret = bk.Permute(new int[3] {
                1, 2, 3
            });

            foreach (var x in perret)
            {
                foreach (var y in x)
                {
                    Console.Write(y);
                    Console.Write(",");
                }
                Console.WriteLine();
            }

            bk.GetFactors(12);

            TreeNode root = new TreeNode(1);
            TreeNode n2   = new TreeNode(2);
            TreeNode n3   = new TreeNode(3);

            root.left  = n2;
            root.right = n3;
            n3.left    = new TreeNode(4);
            n3.right   = new TreeNode(5);

            var bt = new BTree();

            bt.deserialize(bt.serialize(root));
            var ret = bt.FindLeaves(root);

            //var tt = new Thailand();
            //tt.Execute(10, 10);

            var dfs = new DFS_BFS();

            Console.WriteLine("word break");
            Console.WriteLine(dfs.WordBreak("leetcode", new List <string> {
                "leet", "code"
            }));

            Point pt = new Point()
            {
                x = 100, y = 100
            };
            Point pt2 = new Point()
            {
                x = 0, y = 0
            };

            dfs.refSwap(ref pt, ref pt2);
            Console.WriteLine(pt.x + "," + pt.y);
            Console.WriteLine(pt2.x + "," + pt2.y);

            dfs.KillProcess(new List <int> {
                1, 3, 10, 5
            }, new List <int> {
                3, 0, 5, 3
            }, 5);

            asa.GroupAnagrams(new string[] { "eat", "tea", "tan", "ate", "nat", "bat" });
            asa.Compress("AAABBCCCCCCAAAAA");
            asa.LongestIncreasingSubArray(new int[] { 15, 14, 12, 11, 2 });
            asa.ProductExceptSelf(new int[] { 1, 2, 3, 4, });
            //asa.SearchRotatedSortedArray(new int[] { 2,2,2,0,2,2 }, 0);
            asa.MaxSubArray(new int[] { 1, 2, -4, 4, 5, 6 });
            asa.SortColors(new int[] { 1, 2, 0 });
            asa.Equi(new int[] { -1, 3, -4, 5, 1, -6, 2, 1 });


            #region traveler problem
            ////Nearest neighbour algorithm  (Only one messanger)
            //int[,] adjacency_matrix =
            //{
            //    { 0,0, 0, 0, 0, 0 },
            //    { 0,0,50,30,100,10 },
            //    { 0,50,0,5, 20,99999},
            //    { 0,30,5,0, 50,99999 },
            //    { 0,100,20,50,0,10 },
            //    { 0,10,99999,99999,10,0 }
            //};
            //Console.WriteLine("the citys are visited as follows");
            //ImperialMessengersTSPNearestNeighbour tspNearestNeighbour = new ImperialMessengersTSPNearestNeighbour();
            //tspNearestNeighbour.tsp(adjacency_matrix);

            //dijkstra methods
            //int numberNode = 5;
            //string[] shortedPath = new string[numberNode];
            //int[,] G =
            //{
            //    { 0,50,30,100,10 },
            //    { 50,0,5, 20,99999},
            //    { 30,5,0, 50,99999 },
            //    { 100,20,50,0,10 },
            //    { 10,99999,99999,10,0 }
            //};
            //string[] PathResult = new string[numberNode];
            //int[] path1 = new int[numberNode];
            ////int[,] path2 = new int[numberNode, numberNode];
            //int[] distance2 = new int[numberNode];

            //var dijkstra = new Dijkstra();
            //int dist1 = Dijkstra.getShortedPath(G, 0, 1, path1, numberNode);

            //int goThroughAllCities = int.MinValue;
            //for (int i = 1; i < numberNode; i++)
            //{
            //    goThroughAllCities = Math.Max(goThroughAllCities, Dijkstra.getShortedPath(G, 0, i, path1, numberNode));
            //}
            //Console.WriteLine("The min cost of going through all cities is: " + goThroughAllCities);

            //Console.WriteLine("Node 0 To 1:");
            //for (int i = 0; i < path1.Length; i++)
            //    Console.Write(path1[i].ToString() + " ");
            //Console.WriteLine("Length:" + dist1);

            //int[] pathdist = Dijkstra.getShortedPath(G, 0, path2, 5);
            //Console.WriteLine("\nNode 0 To other:");
            //for (int j = 1; j < pathdist.Length; j++)
            //{
            //    Console.WriteLine("Node 0 to " + j + " path:");
            //    for (int i = 0; i < numberNode; i++)
            //    {
            //        Console.Write(path2[j, i].ToString() + " ");
            //    }
            //    Console.WriteLine("length:" + pathdist[j]);
            //}
            #endregion
        }
コード例 #7
0
 private static string __fixArrayStr(ArrayString method)
 {
     return(__fixArrayStr("", method));
 }