Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Letter-frequency/C-sharp/letter-frequency-1.cs
Normal file
37
Task/Letter-frequency/C-sharp/letter-frequency-1.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
static SortedDictionary<TItem, int> GetFrequencies<TItem>(IEnumerable<TItem> items)
|
||||
{
|
||||
var dictionary = new SortedDictionary<TItem, int>();
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (dictionary.ContainsKey(item))
|
||||
{
|
||||
dictionary[item]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
dictionary[item] = 1;
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
static void Main(string[] arguments)
|
||||
{
|
||||
var file = arguments.FirstOrDefault();
|
||||
if (File.Exists(file))
|
||||
{
|
||||
var text = File.ReadAllText(file);
|
||||
foreach (var entry in GetFrequencies(text))
|
||||
{
|
||||
Console.WriteLine("{0}: {1}", entry.Key, entry.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Task/Letter-frequency/C-sharp/letter-frequency-2.cs
Normal file
8
Task/Letter-frequency/C-sharp/letter-frequency-2.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var freq = from c in str
|
||||
where char.IsLetter(c)
|
||||
orderby c
|
||||
group c by c into g
|
||||
select g.Key + ":" + g.Count();
|
||||
|
||||
foreach(var g in freq)
|
||||
Console.WriteLine(g);
|
||||
Loading…
Add table
Add a link
Reference in a new issue