Advertisement
Guest User

Untitled

a guest
Mar 11th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Test
  6. {
  7. class TestGround
  8. {
  9. static void Main(string[] args)
  10. {
  11. string[] input = Console.ReadLine().Split(' ').ToArray();
  12. Dictionary<string, Dictionary<int, double>> myDict = new Dictionary<string, Dictionary<int, double>>();
  13. for (int i = 0; i < input.Length; i++)
  14. {
  15. string current = input[i];
  16. int counter = 1;
  17. for (int j = i + 1; j < input.Length; j++)
  18. {
  19. if (current == input[j])
  20. {
  21. counter++;
  22. }
  23. }
  24. double percent = (counter / (double)input.Length) * 100;
  25. if (!myDict.ContainsKey(current))
  26. {
  27. Dictionary<int, double> inner = new Dictionary<int, double>();
  28. myDict.Add(current, inner);
  29. if (!myDict[current].ContainsKey(counter))
  30. {
  31. myDict[current].Add(counter, percent);
  32. }
  33. }
  34. else
  35. {
  36. continue;
  37. }
  38. }
  39. foreach (var str in myDict.OrderByDescending(x => x.Value.Keys.First()))
  40. {
  41. Console.Write($"{str.Key} -> ");
  42. foreach (var s in str.Value)
  43. {
  44. Console.WriteLine($"{s.Key} times ({s.Value:f2}%)");
  45. }
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement