Advertisement
vasilivanov93

Untitled

Mar 6th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _03.MixedPhones
  5. {
  6. public class MixedPhones
  7. {
  8. public static void Main()
  9. {
  10. SortedDictionary<string, decimal> phoneNumbers = new SortedDictionary<string, decimal>();
  11.  
  12. string line = Console.ReadLine();
  13.  
  14. while (line != "Over")
  15. {
  16. string[] tokens = line.Split(" :".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  17.  
  18. string firstElement = tokens[0];
  19. string secondElement = tokens[1];
  20.  
  21. decimal phoneNumber = 0m;
  22. if (decimal.TryParse(firstElement, out phoneNumber))
  23. {
  24. phoneNumbers[secondElement] = phoneNumber;
  25. }
  26. else if (decimal.TryParse(secondElement, out phoneNumber))
  27. {
  28. phoneNumbers[firstElement] = phoneNumber;
  29. }
  30.  
  31. line = Console.ReadLine();
  32. }
  33.  
  34. foreach (var namePhonePair in phoneNumbers)
  35. {
  36. string name = namePhonePair.Key;
  37. decimal phone = namePhonePair.Value;
  38.  
  39. Console.WriteLine($"{name} -> {phone}");
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement