feat: add "Lab4.RemoveVowels"
This commit is contained in:
parent
8a8b98823f
commit
64a56eca2a
15
Lab4.RemoveVowels/Duomenys.txt
Normal file
15
Lab4.RemoveVowels/Duomenys.txt
Normal file
@ -0,0 +1,15 @@
|
||||
Kūčių rytą
|
||||
|
||||
Anksti Kūčių rytą šeimininkė budina savo vyrą:
|
||||
- Eik greičiau, saulei netekėjus, kur dalgės kabo, ištverk dalges. Dalges
|
||||
padėk po stogu, o dalgiakočius sudėk svirnan.
|
||||
Šeimininkė ieško kubilo lanko, kad būt visai apskritas, nepertrūkęs niekur.
|
||||
Tą lanką neša vištų tvartan, vidury tvarto paguldo. O tada šeimininkė skuba
|
||||
tvartant prie kodžio, kur būna žirniai supilti. Šeimininkė tuos žirnius semia
|
||||
negailėdama didžiulį gorčių, kad visos vištos prilestų lig soties. Šeimininkė
|
||||
pila tuos žirnius tan kubilo lankan, kad nei vienas žirnis nebūt už kubilo
|
||||
lanko - kad vištos visos dėtų kiaušinius vienan daiktan, nemėtytų kiaušinių.
|
||||
Berdama žirnius tan lankan, šeimininkė garsiai sako vištom:
|
||||
- Žiūrėkite, kad nei vieno kiaušinio, nei vieno niekur nepamestut, visus
|
||||
vienon vieton dėkite!
|
||||
Na ir visos vištos šeimininkės įsakymą vykdo.
|
10
Lab4.RemoveVowels/Lab4.RemoveVowels.csproj
Normal file
10
Lab4.RemoveVowels/Lab4.RemoveVowels.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
18
Lab4.RemoveVowels/Program.cs
Normal file
18
Lab4.RemoveVowels/Program.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab4.RemoveVowels
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
const string CFd = "Duomenys.txt";
|
||||
const string CFr = "Rezultatai.txt";
|
||||
const string CFa = "Analize.txt";
|
||||
const string vowels = "AEIYOUaeiyouĄąĘęĖėĮįŲųŪū";
|
||||
char[] punctuation = {' ', '.', ',', '!', '?', ':', ';', '(', ')', '\t'};
|
||||
TaskUtils.Process(CFd, CFr, CFa, punctuation, vowels);
|
||||
}
|
||||
}
|
||||
}
|
74
Lab4.RemoveVowels/TaskUtils.cs
Normal file
74
Lab4.RemoveVowels/TaskUtils.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Lab4.RemoveVowels
|
||||
{
|
||||
class TaskUtils
|
||||
{
|
||||
/** Finds the longest word in the line.
|
||||
@param line – string of data
|
||||
@param punctuation – punctuation marks to separate words */
|
||||
private static string LongestWord(string line, char[] punctuation)
|
||||
{
|
||||
string[] parts = line.Split(punctuation, StringSplitOptions.RemoveEmptyEntries);
|
||||
string longestWord="";
|
||||
foreach (string word in parts)
|
||||
if (word.Length > longestWord.Length)
|
||||
longestWord = word;
|
||||
return longestWord;
|
||||
}
|
||||
|
||||
/** Removes vowels from the given word.
|
||||
@param line – word with possible vowels
|
||||
@param vowels – vowels of the alphabet */
|
||||
private static StringBuilder RemoveVowels(string line, string vowels)
|
||||
{
|
||||
StringBuilder newLine = new StringBuilder();
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
if (vowels.IndexOf(line[i]) == -1)
|
||||
newLine.Append(line[i]);
|
||||
return newLine;
|
||||
}
|
||||
|
||||
/** Reads file, removes vowels from the longest word, creates files of
|
||||
results and of information.
|
||||
@param fin – name of data file
|
||||
@param fout – name of result file
|
||||
@param finfo – name of informative file
|
||||
@param punctuation – punctuation marks to separate words
|
||||
@param vowels – vowels of the alphabet */
|
||||
public static void Process(string fin, string fout, string finfo, char[] punctuation, string vowels)
|
||||
{
|
||||
string[] lines = File.ReadAllLines(fin, Encoding.UTF8);
|
||||
string dashes = new string('-', 38);
|
||||
using (var writerF = File.CreateText(fout))
|
||||
{
|
||||
using (var writerI = File.CreateText(finfo))
|
||||
{
|
||||
writerI.WriteLine(dashes);
|
||||
writerI.WriteLine("| Ilgiausias žodis | Pradžia | Ilgis |");
|
||||
writerI.WriteLine(dashes);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (line.Length > 0)
|
||||
{
|
||||
string longestWord = LongestWord(line, punctuation);
|
||||
string wordNoVowels = RemoveVowels(longestWord, vowels).ToString();
|
||||
writerI.WriteLine("| {0,-16} | {1, 7:d} | {2, 5:d} |",
|
||||
longestWord, line.IndexOf(longestWord), longestWord.Length);
|
||||
string newLine = line.Replace(longestWord, wordNoVowels);
|
||||
// The shortest word cannot be replaced this way.
|
||||
// It can be a part of the other word; solution is 4.5 subsection.
|
||||
writerF.WriteLine(newLine);
|
||||
}
|
||||
else
|
||||
writerF.WriteLine(line);
|
||||
}
|
||||
writerI.WriteLine(dashes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
Lab4.sln
6
Lab4.sln
@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.FirstEqualLast", "Lab4
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.AddSurname", "Lab4.AddSurname\Lab4.AddSurname.csproj", "{F7EFA186-AD5D-4E5D-B405-9ACBAEDB7BF3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.RemoveVowels", "Lab4.RemoveVowels\Lab4.RemoveVowels.csproj", "{5AD87F42-DD6D-4ADF-B1D5-66553BAA4BCC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -43,6 +45,10 @@ Global
|
||||
{F7EFA186-AD5D-4E5D-B405-9ACBAEDB7BF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F7EFA186-AD5D-4E5D-B405-9ACBAEDB7BF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F7EFA186-AD5D-4E5D-B405-9ACBAEDB7BF3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5AD87F42-DD6D-4ADF-B1D5-66553BAA4BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5AD87F42-DD6D-4ADF-B1D5-66553BAA4BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5AD87F42-DD6D-4ADF-B1D5-66553BAA4BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5AD87F42-DD6D-4ADF-B1D5-66553BAA4BCC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user