Created
January 16, 2012 16:27
-
-
Save aviatrix/1621632 to your computer and use it in GitHub Desktop.
Calculating density of characters and printing them in hi-to-low manner
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
/* | |
sample input : aazzaaffggghhtzzz | |
sample output : zzzzzaaaagggffhht | |
*/ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace task1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Въведете низ :"); | |
var text = Console.ReadLine(); | |
var list = new Dictionary<char, int>(); | |
for (int i = 0; i < text.Count(); i++) | |
{ | |
if (!list.ContainsKey(text[i])) | |
{ | |
var num = text.Where(x => x.Equals(text[i])).Count(); | |
list.Add(text[i], num); | |
} | |
} | |
foreach (var i in list.OrderByDescending(x => x.Value)) | |
{ | |
for (int j = 0; j < i.Value; j++) | |
{ | |
Console.Write(i.Key); | |
} | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
what about linq ?
I just answer myself after viewing the imports in begging after writing the comment :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
linq?