Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solución Reto #7 C# #1274

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex =S
siento que me va a dar un derrame pensando en expresiones regulares :/
Utilice árboles binarios en la solución B)
https://github.com/lonchanick/MoureDevWeeklyChallenge/blob/master/Challenges/Challenge7.cs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jajaja, bien :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Challenge #7
* COUNTING WORDS
* Difficulty: MEDIUM
*
* Statement: Create a program that counts how many times each word is repeated and displays the final count for all of them.
* - Punctuation marks are not part of the word.
* - A word is the same even if it appears in upper and lower case.
* - It is not possible to use functions of the language that resolve it automatically.
*
* Reto #7
* CONTANDO PALABRAS
* Dificultad: MEDIA
*
* Enunciado: Crea un programa que cuente cuantas veces se repite cada palabra y que muestre el recuento final de todas ellas.
* - Los signos de puntuación no forman parte de la palabra.
* - Una palabra es la misma aunque aparezca en mayúsculas y minúsculas.
* - No se pueden utilizar funciones propias del lenguaje que lo resuelvan automáticamente.
*/
using System.Text.RegularExpressions;

void CountWordsRepetitions(string text)
{
string[] textSplitted = text.Split(" ");
Dictionary<string, int> wordDetail = new Dictionary<string, int>();
Regex regex = new Regex(@"\p{P}");

foreach (string word in textSplitted)
{
string wordCleaned = regex.Replace(word, "").ToLower();
if (wordDetail.ContainsKey(wordCleaned) == false) wordDetail.Add(wordCleaned, 1);
else wordDetail[wordCleaned] += 1;
}
Console.WriteLine("************ Word: Repetitions ************");
foreach (var word in wordDetail) Console.WriteLine($"{word.Key}: {word.Value}");
int finalCount = wordDetail.Values.Sum();
Console.Write($"Final words count: {finalCount}");
}
CountWordsRepetitions("Hello World. Hello, hello world");
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>