IPetrov007

MixedPhones

Mar 5th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03_MixedPhones
  8. {
  9. class MixedPhones
  10. {
  11. static void Main(string[] args)
  12. {
  13. var result = new SortedDictionary<string, long>();
  14. string inputStr = Console.ReadLine();
  15.  
  16. while (inputStr != "Over")
  17. {
  18. var input = inputStr
  19. .Split(
  20. new[] {' '},
  21. StringSplitOptions.RemoveEmptyEntries);
  22.  
  23. long phoneNumber;
  24. long.TryParse(input[0], out phoneNumber);
  25.  
  26. if (phoneNumber != 0)
  27. {
  28. result.Add(input[2].Trim(), phoneNumber);
  29. }
  30. else
  31. {
  32. result.Add(input[0].Trim(), long.Parse(input[2]));
  33. }
  34.  
  35. inputStr = Console.ReadLine();
  36. }
  37. foreach (var kvp in result.Keys)
  38. {
  39. Console.WriteLine($"{kvp} -> {result[kvp]}");
  40.  
  41. }
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment