Advertisement
Guest User

Untitled

a guest
Feb 12th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04._Array_Histogram
  6. {
  7. class ArrayHistogram
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> seqence = Console.ReadLine().Split().ToList();
  12. Dictionary<string, Dictionary<int, double>> dict = new Dictionary<string, Dictionary<int, double>>();
  13.  
  14. for (int i = 0; i < seqence.Count; i++)
  15. {
  16. int count = 1;
  17. string word = seqence[i];
  18. for (int j = i + 1; j < seqence.Count ; j++)
  19. {
  20. if (seqence[i] == seqence[j])
  21. {
  22. count++;
  23. }
  24. }
  25. if (!dict.ContainsKey(seqence[i]))
  26. {
  27. double percent=((double)count / seqence.Count)*100;
  28. dict.Add(word, new Dictionary<int, double>());
  29. dict[word].Add(count,percent);
  30. }
  31. }
  32.  
  33. foreach (var word in dict)
  34. {
  35. foreach (var num in word.Value.OrderByDescending(x=>x.Value))
  36. {
  37. Console.WriteLine($"{word.Key} -> {num.Key} times ({num.Value:f2}%)");
  38. }
  39. }
  40.  
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement