Hva gjør koden

This commit is contained in:
Geir Okkenhaug Jerstad 2024-11-19 14:30:51 +01:00
parent 2c3f93d0c4
commit 3cb41d15d7
3 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp10HvaGjørKoden", "ConsoleApp10HvaGjørKoden.csproj", "{9146E1AB-594E-4929-A80F-0EE9AAA85311}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,26 @@
var range = 250;
var counts = new int[range];
int totalLetters = 0;
string text = "something";
while (!string.IsNullOrWhiteSpace(text))
{
text = Console.ReadLine();
Console.Clear();
foreach (var character in text.ToLower() ?? string.Empty)
{
totalLetters++;
counts[(int)character]++;
}
for (var i = 0; i < range; i++)
{
if (counts[i] > 0)
{
// Måtte jukse litt for jeg hadde: var percentage = counts[i] / totalLetters * 100; som var feil matte
var character = (char)i;
var percentage = 100 * counts[i] / totalLetters ;
// string output = counts[i] + " - " + character + " - " + percentage + "%";
Console.WriteLine(String.Format("{0,0} - {1,1} - {2,2}%", counts[i], character, percentage));
}
}
}