Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MixedPhones
- {
- class Program
- {
- static void Main(string[] args)
- {
- SortedDictionary<string, long> phones = new SortedDictionary<string, long>();
- string[] input = Console.ReadLine().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries);
- while (input[0] != "Over")
- {
- string keyInput = input[0];
- string valueInput = input[1];
- long numValue = 0;
- long numValue2 = 0;
- bool testParse = (long.TryParse(keyInput, out numValue));
- bool testparse2 = (long.TryParse(valueInput, out numValue2));
- if (testParse == true)
- {
- phones[valueInput] = numValue;
- }
- else
- {
- if (phones.ContainsKey(valueInput))
- {
- phones[keyInput] = phones[valueInput];
- }
- }
- if (testparse2 == true)
- {
- phones[keyInput] = numValue2;
- if (phones.ContainsKey(valueInput))
- {
- phones[keyInput] = phones[valueInput];
- }
- }
- input = Console.ReadLine().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries);
- }
- foreach (KeyValuePair<string, long> item in phones)
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement