2024-11-19 14:30:51 +01:00
|
|
|
|
var range = 250;
|
|
|
|
|
var counts = new int[range];
|
|
|
|
|
int totalLetters = 0;
|
|
|
|
|
string text = "something";
|
|
|
|
|
while (!string.IsNullOrWhiteSpace(text))
|
|
|
|
|
{
|
|
|
|
|
text = Console.ReadLine();
|
|
|
|
|
Console.Clear();
|
2024-11-19 14:47:41 +01:00
|
|
|
|
Console.WriteLine(String.Format("{0,-6} - {1,-7} - {2,-7}", "Antall", "Bokstav", "Prosent"));
|
2024-11-19 14:30:51 +01:00
|
|
|
|
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 + "%";
|
2024-11-19 14:47:41 +01:00
|
|
|
|
|
|
|
|
|
Console.WriteLine(String.Format("{0,-6} - {1,-7} - {2,-7}", counts[i], character, percentage + "%"));
|
2024-11-19 14:30:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|