BubaLazi

DictionariesEX03MixedPhones

Jul 28th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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 ArraysAndLists
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {            
  13.             SortedDictionary<string, long> phonebook = new SortedDictionary<string, long>();
  14.             string[] input = Console.ReadLine().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  15.  
  16.             while(input[0] != "Over")
  17.             {
  18.                 string nameInput = String.Empty;
  19.                 long phoneNumber = 0;
  20.  
  21.                 if (long.TryParse(input[0], out phoneNumber))
  22.                 {
  23.                     nameInput = input[1];
  24.                     phonebook[nameInput] = phoneNumber;                    
  25.                 }
  26.  
  27.                 if (long.TryParse(input[1], out phoneNumber))
  28.                 {
  29.                     nameInput = input[0];                    
  30.                     phonebook[nameInput] = phoneNumber;
  31.                 }
  32.                
  33.                
  34.                 input = Console.ReadLine().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  35.             }
  36.  
  37.             foreach(KeyValuePair<string,long> item in phonebook)
  38.             {
  39.                 Console.WriteLine($"{item.Key} -> {item.Value}");
  40.             }
  41.         }        
  42.        
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment