-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
NaDisla
wants to merge
1
commit into
mouredev:main
Choose a base branch
from
NaDisla:nadisla-challenge07-csharp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Solución Reto #7 C# #1274
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/nadisla/weeklychallenge2022/challenge07-csharp/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/nadisla/weeklychallenge2022/challenge07-csharp/challenge07.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jajaja, bien :)