1
0

feat: add "Lab4.AddSurname"

This commit is contained in:
Rokas Puzonas 2021-11-22 01:52:43 +02:00
parent eaed3f058f
commit c731d76fe0
5 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,9 @@
Arvydas (g. 1964 m. gruodžio 19 d. Kaune) Lietuvos krepšininkas,
olimpinis ir pasaulio čempionas Arvydas, nuo Arvydas
2011 m. spalio 24 d. Lietuvos krepšinio federacijos prezidentas.
Profesionalaus žaidėjo karjerą Arvydas pradėjo 1981 m.
Kauno krepšinio klube "Žalgiris".
Arvydas tris sezonus iš eilės (19851987 m.). Arvydas
padėjo komandai iškovoti SSRS krepšinio čempionato aukso medalius.
1982 m. Arvydas SSRS rinktinės Arvydas sudėtyje Arvydas
dalyvavo pasaulio krepšinio čempionate ir laimėjo auksą.

View 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>

View File

@ -0,0 +1,16 @@

namespace Lab4.AddSurname
{
public class Program
{
public static void Main(string[] args)
{
const string CFd = "Duomenys.txt";
const string CFr = "Rezultatai.txt";
string punctuation = " .,!?:;()\t'";
string name = "Arvydas";
string surname = "Sabonis";
TaskUtils.Process(CFd, CFr, punctuation, name, surname);
}
}
}

View File

@ -0,0 +1,52 @@
using System.Text;
using System.IO;
namespace Lab4.AddSurname
{
public class TaskUtils
{
/** Finds name in the line and constructs new line appending given surname.
@param line string of data
@param punctuation punctuation marks to separate words
@param name word to find
@param surname given word to add
@param newLine string of result */
private static void AddSurname(string line, string punctuation, string name, string surname, StringBuilder newLine)
{
string addLine = " " + line + " ";
int init = 1;
int ind = addLine.IndexOf(name);
while (ind != -1)
{
if (punctuation.IndexOf(addLine[ind - 1]) != -1 && punctuation.IndexOf(addLine[ind + name.Length]) != -1)
{
newLine.Append(addLine.Substring(init, ind + name.Length - init));
newLine.Append(surname);
init = ind + name.Length;
}
ind = addLine.IndexOf(name, ind + 1);
}
newLine.Append(line.Substring(init - 1));
}
/** Reads file and adds given surname to the given name.
@param fin name of data file
@param fout name of result file
@param punctuation punctuation marks to separate words
@param name word to find
@param surname given word to add */
public static void Process(string fin, string fout, string punctuation, string name, string surname)
{
string[] lines = File.ReadAllLines(fin, Encoding.UTF8);
using (var writer = File.CreateText(fout))
{
foreach (string line in lines)
{
StringBuilder newLine = new StringBuilder();
AddSurname(line, punctuation, name, surname, newLine);
writer.WriteLine(newLine);
}
}
}
}
}

View File

@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.LetterFrequency", "Lab
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.FirstEqualLast", "Lab4.FirstEqualLast\Lab4.FirstEqualLast.csproj", "{83CB5DEC-25E5-42FF-8601-9BF8DA73E397}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.AddSurname", "Lab4.AddSurname\Lab4.AddSurname.csproj", "{F7EFA186-AD5D-4E5D-B405-9ACBAEDB7BF3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -37,6 +39,10 @@ Global
{83CB5DEC-25E5-42FF-8601-9BF8DA73E397}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83CB5DEC-25E5-42FF-8601-9BF8DA73E397}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83CB5DEC-25E5-42FF-8601-9BF8DA73E397}.Release|Any CPU.Build.0 = Release|Any CPU
{F7EFA186-AD5D-4E5D-B405-9ACBAEDB7BF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE