-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathReadAndSort.cs
More file actions
30 lines (27 loc) · 902 Bytes
/
ReadAndSort.cs
File metadata and controls
30 lines (27 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Startup
{
static void Main()
{
string keyAlphabet = "abc~WITHSOMEADDITIONALLCHARACTERS~yz_";
string keyInput = File.ReadAllText(@"C:\Input.txt");
Dictionary<string, long> countDic= new Dictionary<string, long>();
for (int i = 0; i < keyAlphabet.Count(); i++)
{
countDic.Add(keyAlphabet[i].ToString(), 0);
}
for (int i = 0; i < keyInput.Count(); i++)
{
if (countDic.ContainsKey(keyInput[i].ToString()))
{
long countDicSize = countDic[keyInput[i].ToString()];
countDic[keyInput[i].ToString()] = countDicSize + 1;
}
}
var ordered = countDic.OrderBy(x => x.Value).Reverse();
Console.WriteLine(String.Join("",ordered.ToArray()));
}
}