Advertisement
Aborigenius

MixedPhones

Jul 9th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 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 MixedPhones
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             SortedDictionary<string, long> phones = new SortedDictionary<string, long>();
  14.             string[] input = Console.ReadLine().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries);
  15.  
  16.             while (input[0] != "Over")
  17.             {
  18.                 string keyInput = input[0];
  19.                 string valueInput = input[1];
  20.                 long numValue = 0;
  21.                 long numValue2 = 0;
  22.                 bool testParse = (long.TryParse(keyInput, out numValue));
  23.                 bool testparse2 = (long.TryParse(valueInput, out numValue2));
  24.                 if (testParse == true)
  25.                 {
  26.                     phones[valueInput] = numValue;
  27.                 }
  28.                 else
  29.                 {
  30.                     if (phones.ContainsKey(valueInput))
  31.                     {
  32.                         phones[keyInput] = phones[valueInput];
  33.                     }
  34.                 }
  35.                 if (testparse2 == true)
  36.                 {
  37.                     phones[keyInput] = numValue2;
  38.  
  39.                     if (phones.ContainsKey(valueInput))
  40.                     {
  41.                         phones[keyInput] = phones[valueInput];
  42.                     }
  43.                 }
  44.  
  45.                 input = Console.ReadLine().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries);
  46.             }
  47.             foreach (KeyValuePair<string, long> item in phones)
  48.             {
  49.                 Console.WriteLine($"{item.Key} -> {item.Value}");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement