Example #1
0
        public static void Show()
        {
            #region 找零问题
            {
                double origAmount   = 0.63;//原始总金额
                double toChange     = origAmount;
                double remainAmount = 0.0;
                int[]  coins        = new int[4];//4种面值 1-5-10-25
                MakeChange(origAmount, remainAmount, coins);
            }
            #endregion

            #region  夫曼
            {
                string input;
                Console.Write("请输入一个字符串: ");
                input = Console.ReadLine();
                TreeList treeList = new TreeList(input);
                for (int i = 0; i < input.Length; i++)
                {
                    treeList.AddSign(input[i].ToString());
                }
                treeList.SortTree();
                while (treeList.Length() > 1)
                {
                    treeList.MergeTree();
                }
                TreeList.MakeKey(treeList.RemoveTree(), "");
                string   newStr    = TreeList.Translate(input);
                string[] signTable = treeList.GetSignTable();
                string[] keyTable  = treeList.GetKeyTable();
                for (int i = 0; i <= signTable.Length - 1; i++)
                {
                    Console.WriteLine(signTable[i] + ": " + keyTable[i]);
                }

                Console.WriteLine("The original string is " + input.Length * 16 + " bits long.");
                Console.WriteLine("The new string is " + newStr.Length + " bits long.");
                Console.WriteLine("The coded string looks like this:" + newStr);
            }
            #endregion

            #region MyRegion
            {
                Carpet    c1   = new Carpet("Frieze", 1.75F, 12);
                Carpet    c2   = new Carpet("Saxony", 1.82F, 9);
                Carpet    c3   = new Carpet("Shag", 1.5F, 13);
                Carpet    c4   = new Carpet("Loop", 1.77F, 10);
                ArrayList rugs = new ArrayList();
                rugs.Add(c1);
                rugs.Add(c2);
                rugs.Add(c3);
                rugs.Add(c4);
                rugs.Sort();
                Knapsack k = new Knapsack(25);
                k.FillSack(rugs);
                Console.WriteLine(k.GetItems());
            }
            #endregion
        }