Advertisement
Guest User

Couples Frequency

a guest
Oct 3rd, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. class UserLogs
  8. {
  9. static void Main()
  10. {
  11. string input = Console.ReadLine();
  12. string pattern = @"\s+";
  13. string[] substrings = Regex.Split(input, pattern);
  14.  
  15. Dictionary<string, int> combinations = new Dictionary<string, int>();
  16. for (int i = 0; i < substrings.Length - 1; i++)
  17. {
  18. if (combinations.ContainsKey(substrings[i] + " " + substrings[i + 1]))
  19. {
  20. int currentValue = combinations[substrings[i] + " " + substrings[i + 1]];
  21. combinations[substrings[i] + " " + substrings[i + 1]] = currentValue + 1;
  22. }
  23. else
  24. {
  25. combinations.Add(substrings[i] + " " + substrings[i + 1], 1);
  26. }
  27. }
  28.  
  29. int total = 0;
  30.  
  31. foreach (var item in combinations)
  32. {
  33. total += item.Value;
  34. }
  35.  
  36. foreach (var item in combinations)
  37. {
  38. Console.WriteLine("{0} -> {1:F2}%", item.Key, ((double)item.Value / (double)total) * 100);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement