Advertisement
DimitarP

04. Array Histogram_100points

Sep 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace AL41
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] inputWords = Console.ReadLine().Split(' ').ToArray();
  14. int inputWordsCount = inputWords.Length;
  15. Dictionary<string, int> wordsAndCounts = new Dictionary<string, int>();
  16. foreach(string word in inputWords)
  17. {
  18. if (wordsAndCounts.ContainsKey(word))
  19. {
  20. wordsAndCounts[word]++;
  21. }
  22. else
  23. {
  24. wordsAndCounts.Add(word, 1);
  25. }
  26. }
  27. var Sorted = wordsAndCounts.OrderByDescending(x => x.Value);
  28. foreach (var item in Sorted)
  29. {
  30. double percentage = (double)item.Value / inputWordsCount * 100;
  31. Console.WriteLine($"{item.Key} -> {item.Value} times ({percentage:F2}%)");
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement