예제 #1
0
        public void shah()
        {
            if (readFile() == true)
            {
                //Console.WriteLine(str);
                foreach (char currentChar in strs)
                {
                    if (Dawtamj.ContainsKey(currentChar.ToString()))
                    { Dawtamj[currentChar.ToString()]++; }
                    else
                    { Dawtamj.Add(currentChar.ToString(), 1); }
                }
                daraalal dar = new daraalal();

                foreach (KeyValuePair<String, int> kvp in Dawtamj)
                {
                    BinaryTree b = new BinaryTree();
                    b.insert(Tuple.Create(kvp.Key, kvp.Value));
                    dar.oruul(b);

                }
                dar.Uusge();

                foreach (KeyValuePair<String, int> kvp in Dawtamj)
                {
                    if (kvp.Key.CompareTo(" ") == 0)
                        Code_hus.Add("*", Display1(dar.asdqwe().root1(), kvp.Key, ""));
                    else
                        Code_hus.Add(kvp.Key, Display1(dar.asdqwe().root1(), kvp.Key, ""));
                }

                String ner = str.Substring(0, str.Length - 4) + ".pjl";

                using (StreamWriter writer = new StreamWriter(ner))
                {
                    writer.Write(Nuutsal(Code_hus.Count.ToString()) +"\n");
                    foreach (KeyValuePair<String, String> kvp in Code_hus)
                    {
                        writer.Write(Nuutsal(kvp.Key + " " + kvp.Value) + "\n");

                        //Console.WriteLine("Code {0}:\t{1}", kvp.Key, kvp.Value);
                      //  richTextBox1.Text = richTextBox1.Text + kvp.Key + " " + kvp.Value + "\n";
                    }

                    for (int i = 0; i < strs.Length; i++)
                    {
                        if (strs.Substring(i, 1).CompareTo(" ") == 0)
                        {
                            String code = Code_hus["*"];
                            shine = shine + code;//.PadLeft(6,'0');
                        }
                        else {
                            String code = Code_hus[strs.Substring(i, 1)];
                            shine = shine + code;
                        }
                    }
                    for(int i = 0; i < shine.Length; i = i + 8)
                    {
                        String a;
                        if (shine.Length - i < 8) a = shine.Substring(i, shine.Length - i);
                        else a = shine.Substring(i, 8);
                        String baa = bintodec(a).ToString();
                        //baa = baa.PadLeft(3, '0');
                        int baa1 = Int32.Parse(baa);
                        char baa3 = (char)baa1;
                        String baa2 = baa3.ToString();
                        writer.Write(Nuutsal(baa2));
                    }
                }
            }
            else
            {
                MessageBox.Show( "Та .txt өргөтгөлтэй файл сонгоно уу?","Алдаа" ,MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }