public void Deti(int i, int j, Simboliai a) { Simb[i, j] = a; }
/// <summary> /// Skaito duomenis is duom failu /// </summary> /// <param name="simboliai">simboliu konteineris</param> /// <param name="zodziuMasyvas">duotuju zodziu masyvas</param> /// <param name="n">matricos dydis n*n</param> /// <param name="zodziuC">kiek yra duotuju zodziu</param> public void Skaityti(Konteinerine simboliai, string[] zodziuMasyvas, out int zodziuC, out int nn) { int MaxEil = 50; string line; int simboliuSk = 0; string[] eilutes = new string[MaxEil]; int teksEil = 0; // kiek duotam faile yra eiluciu using (StreamReader reader = new StreamReader(f1)) { while ((line = reader.ReadLine()) != null) { simboliuSk += line.Length; eilutes[teksEil++] = line; } } //------------randa kvadratines matricos n x n double n = Math.Sqrt(simboliuSk); n = Math.Round(n, 1); if (n % Math.Round(n, 0) == 0) { n = Math.Round(n, 0); } else { if (n % Math.Round(n, 0) >= 0.5) { n = Math.Round(n, 0); } else { n = n = Math.Round(n, 0) + 1; } } //------------sudeda teksta i viena eilute nn = Convert.ToInt32(n); string failas = ""; for (int i = 0; i < teksEil; i++) { failas = failas + eilutes[i]; } //------------slpit'ina kas simboli ir deda i kvadratine matrica string[] sym = new string[simboliuSk]; char[] symbol = failas.ToCharArray(); int count = 0; char a; for (int jj = 0; jj < n; jj++) { for (int ii = 0; ii < n; ii++) { if (count < failas.Length) { a = symbol[count]; } else { a = ' '; } Simboliai ss = new Simboliai(a); simboliai.Deti(ii, jj, ss); count++; } } //-------------skaito antro failo zodzius zodziuC = 0; string line1; string eilZod = ""; using (StreamReader reader = new StreamReader(f2)) { while ((line1 = reader.ReadLine()) != null) { if (line1.Length <= n / 2) { zodziuMasyvas[zodziuC++] = line1; } eilZod += line1 + "\r\n"; } } if (File.Exists(f3)) { File.Delete(f3); } //------------suraso pradinius duomenis i rezultatu faila string eil = ""; using (var writer = File.AppendText(f3)) { writer.WriteLine("Duotas tekstas: "); writer.WriteLine(); for (int i = 0; i < teksEil; i++) { writer.WriteLine(eilutes[i]); } writer.WriteLine("----------------------------------"); writer.WriteLine(); writer.WriteLine("Zodziu matrica "); writer.WriteLine(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { writer.Write(" " + simboliai.Imti(j, i).s); eil += " " + simboliai.Imti(j, i).s; } writer.WriteLine(); eil += "\r\n"; } writer.WriteLine("----------------------------------"); writer.WriteLine(); writer.WriteLine("Duoti zodziai:"); writer.WriteLine(); for (int i = 0; i < zodziuC; i++) { writer.WriteLine(zodziuMasyvas[i]); } writer.WriteLine("----------------------------------"); TextBox1.Text = eil; TextBox2.Text = "Pradiniai duomenys"; TextBox5.Text = "Duoti zodziai"; TextBox4.Text = eilZod; } }