Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. string sentence = Console.ReadLine();
  6.  
  7. Dictionary<string, int> result = new Dictionary<string, int>();
  8.  
  9. for(int i = 0; i < sentence.Count() - 1; i++)
  10. {
  11. char current = sentence.ElementAt(i);
  12. char next = sentence.ElementAt(i + 1);
  13.  
  14. if(current == next)
  15. {
  16. string pair = current.ToString() + next.ToString();
  17. if(result.ContainsKey(pair))
  18. {
  19. result[pair]++;
  20. } else
  21. {
  22. result.Add(pair, 1);
  23. }
  24. }
  25. }
  26.  
  27. var value = result.Values.Max();
  28. var key = result.Keys.Where(x => result[x] == value && x != " ").Min();
  29.  
  30. Console.WriteLine(key);
  31. Console.ReadLine();
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement