feat: add Lab4.RemoveLines
This commit is contained in:
parent
e262563742
commit
cc64b2190f
10
Lab4.RemoveLines/Duomenys.txt
Normal file
10
Lab4.RemoveLines/Duomenys.txt
Normal file
@ -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.
|
95
Lab4.RemoveLines/InOut.cs
Normal file
95
Lab4.RemoveLines/InOut.cs
Normal file
@ -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<int> LongestLines(string fin)
|
||||
{
|
||||
List<int> lines = new List<int>();
|
||||
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<int> 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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
Lab4.RemoveLines/Lab4.RemoveLines.csproj
Normal file
14
Lab4.RemoveLines/Lab4.RemoveLines.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Duomenys.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
20
Lab4.RemoveLines/Program.cs
Normal file
20
Lab4.RemoveLines/Program.cs
Normal file
@ -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<int> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
Lab4.sln
14
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
|
||||
|
Loading…
Reference in New Issue
Block a user