Advertisement
Guest User

Untitled

a guest
Mar 11th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 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, int> myDict = new Dictionary<string, int>();
  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, counter);
  29. }
  30. }
  31. foreach (var str in myDict.OrderByDescending(x => x.Value))
  32. {
  33. double percent = (double)str.Value / input.Length * 100;
  34. Console.Write($"{str.Key} -> ");
  35. Console.WriteLine($"{str.Value} times ({percent:f2}%)");
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement