diff --git a/Lab4.RemoveLines/Duomenys.txt b/Lab4.RemoveLines/Duomenys.txt new file mode 100644 index 0000000..9202125 --- /dev/null +++ b/Lab4.RemoveLines/Duomenys.txt @@ -0,0 +1,10 @@ +Aš atverčiau knygą kur pakliuvo. +Raidžių formos man buvo niekur nematytos. +Puslapiai apšiurę, raidės neryškios, tekstas ėjo dviem skiltimis. +Puslapiai apšiurę, raidės neryškios, tekstas ėjo dviem skiltimis. +Šriftas buvo tankus ir padalytas į pastraipas. +Ir mažas paveikslėlis, toks, koks pasitaiko žodynuose: +plunksna nupieštas inkaras, bet lyg negrabia vaiko ranka. +Puslapiai apšiurę, raidės neryškios, tekstas ėjo dviem skiltimis. + + Jorge Luis Borges. Smėlio knyga. Vilnius, 2006. \ No newline at end of file diff --git a/Lab4.RemoveLines/InOut.cs b/Lab4.RemoveLines/InOut.cs new file mode 100644 index 0000000..094d744 --- /dev/null +++ b/Lab4.RemoveLines/InOut.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace Lab4.RemoveLines +{ + class InOut + { + public static int LongestLine(string fin) + { + int No = -1; + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int length = 0; + int lineNo = 0; + while ((line = reader.ReadLine()) != null) + { + if (line.Length > length) + { + length = line.Length; + No = lineNo; + } + lineNo++; + } + } + return No; + } public static List LongestLines(string fin) + { + List lines = new List(); + int longestLength = 0; + + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int lineNo = 0; + while ((line = reader.ReadLine()) != null) + { + if (line.Length > longestLength) + { + longestLength = line.Length; + lines.Clear(); + lines.Add(lineNo); + } + else if (line.Length == longestLength) + { + lines.Add(lineNo); + } + lineNo++; + } + } + + return lines; + } public static void RemoveLine(string fin, string fout, int No) + { + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int lineNo = 0; + using (var writer = File.CreateText(fout)) + { + while ((line = reader.ReadLine()) != null) + { + if (No != lineNo) + { + writer.WriteLine(line); + } + lineNo++; + } + } + } + } + + public static void RemoveLines(string fin, string fout, List lines) + { + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int lineNo = 0; + using (var writer = File.CreateText(fout)) + { + while ((line = reader.ReadLine()) != null) + { + if (!lines.Contains(lineNo)) + { + writer.WriteLine(line); + } + lineNo++; + } + } + } + } + } +} diff --git a/Lab4.RemoveLines/Lab4.RemoveLines.csproj b/Lab4.RemoveLines/Lab4.RemoveLines.csproj new file mode 100644 index 0000000..3a26489 --- /dev/null +++ b/Lab4.RemoveLines/Lab4.RemoveLines.csproj @@ -0,0 +1,14 @@ + + + + Exe + netcoreapp2.1 + + + + + PreserveNewest + + + + diff --git a/Lab4.RemoveLines/Program.cs b/Lab4.RemoveLines/Program.cs new file mode 100644 index 0000000..7eb6f5b --- /dev/null +++ b/Lab4.RemoveLines/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +namespace Lab4.RemoveLines +{ + class Program + { + static void Main(string[] args) + { + const string CFd = "Duomenys.txt"; + const string CFr = "Rezultatai.txt"; + List lines = InOut.LongestLines(CFd); + InOut.RemoveLines(CFd, CFr, lines); + foreach (int line in lines) + { + Console.WriteLine("Ilgiausios eilutės nr. {0, 4:d}", line + 1); + } + } + } +} diff --git a/Lab4.sln b/Lab4.sln index d1e91cf..50b9c14 100644 --- a/Lab4.sln +++ b/Lab4.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28307.1525 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.RemoveLines", "Lab4.RemoveLines\Lab4.RemoveLines.csproj", "{5309D21D-2A14-4332-90EC-504AD89CE397}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.LetterFrequency", "Lab4.LetterFrequency\Lab4.LetterFrequency.csproj", "{F1797B5C-1541-4821-9485-7C3520C5DD8D}" EndProject Global @@ -15,6 +17,18 @@ Global {1966BAA5-C5E8-4F18-A1CB-69A0B2FFD5CE}.Debug|Any CPU.Build.0 = Debug|Any CPU {1966BAA5-C5E8-4F18-A1CB-69A0B2FFD5CE}.Release|Any CPU.ActiveCfg = Release|Any CPU {1966BAA5-C5E8-4F18-A1CB-69A0B2FFD5CE}.Release|Any CPU.Build.0 = Release|Any CPU + {5309D21D-2A14-4332-90EC-504AD89CE397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5309D21D-2A14-4332-90EC-504AD89CE397}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5309D21D-2A14-4332-90EC-504AD89CE397}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5309D21D-2A14-4332-90EC-504AD89CE397}.Release|Any CPU.Build.0 = Release|Any CPU + {4D9B08C9-5735-4C95-8D2A-BDFC888B1E68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D9B08C9-5735-4C95-8D2A-BDFC888B1E68}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D9B08C9-5735-4C95-8D2A-BDFC888B1E68}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D9B08C9-5735-4C95-8D2A-BDFC888B1E68}.Release|Any CPU.Build.0 = Release|Any CPU + {F1797B5C-1541-4821-9485-7C3520C5DD8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1797B5C-1541-4821-9485-7C3520C5DD8D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1797B5C-1541-4821-9485-7C3520C5DD8D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1797B5C-1541-4821-9485-7C3520C5DD8D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE