1
0

feat: add "Lab4.FirstEqualLast" using strings

This commit is contained in:
Rokas Puzonas 2021-11-22 01:26:55 +02:00
parent 9ecf4ff17c
commit 3ca49e564a
5 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,9 @@
V. M. Putinas
Margi sakalai
Lydėdami gęstančią žarą vėlai
Pakilo į dangų;;, margi sakalai.
Paniekinę žemės vylingus sapnus,
Padangėje ištiesė,,; savo sparnus.
Ir tarė margieji: negrįšim į žemę,
Kol josios kalnai ir pakalnės aptemę.
...

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,15 @@
using System;
using System.Collections.Generic;
namespace Lab4.FirstEqualLast
{
public class Program
{
public static void Main(string[] args)
{
const string CFd = "Duomenys.txt";
char [] punctuation = {' ','.',',','!','?',':',';','(',')','\t'};
Console.WriteLine("Sutampančių žodžių {0, 3:d}", TaskUtils.Process(CFd, punctuation));
}
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Lab4.FirstEqualLast
{
public class TaskUtils
{
/** Reads file and finds the number of words having same the first and
the last letters.
@param fin name of data file
@param punctuation punctuation marks to separate words */
public static int Process(string fin, char[] punctuation)
{
string[] lines = File.ReadAllLines(fin, Encoding.UTF8);
int equal = 0;
foreach (string line in lines)
if (line.Length > 0)
equal += FirstEqualLast(line, punctuation);
return equal;
}
/** Splits line into words and counts the words having same the first and the
last letters.
@param line string of data
@param punctuation punctuation marks to separate words */
private static int FirstEqualLast (string line, char[] punctuation)
{
string[] parts = line.Split(punctuation,
StringSplitOptions.RemoveEmptyEntries);
int equal = 0;
foreach (string word in parts)
if (word[0] == word[word.Length - 1])
equal++;
return equal;
}
}
}

View File

@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab4.RemoveComments", "Lab4
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.LetterFrequency", "Lab4.LetterFrequency\Lab4.LetterFrequency.csproj", "{F1797B5C-1541-4821-9485-7C3520C5DD8D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.FirstEqualLast", "Lab4.FirstEqualLast\Lab4.FirstEqualLast.csproj", "{83CB5DEC-25E5-42FF-8601-9BF8DA73E397}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -31,6 +33,10 @@ Global
{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
{83CB5DEC-25E5-42FF-8601-9BF8DA73E397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE