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;
- //You will be given several phone entries, in the form of strings in format:
- //{firstElement} : {secondElement}
- //The first element is usually the person’s name, and the second one – his phone number. The phone number consists ONLY of digits, //while the person’s name can consist of any ASCII characters.
- //Sometimes the phone operator gets distracted by the Minesweeper she plays all day, and gives you first the phone, and then the name. //e.g. : 0888888888 : Pesho. You must store them correctly, even in those cases.
- //When you receive the command “Over”, you are to print all names you’ve stored with their phones. The names must be printed in //alphabetical order.
- namespace Mixed_phones
- {
- class Program
- {
- static void Main(string[] args)
- {
- SortedDictionary<string, long> phonebook = new SortedDictionary<string, long>();
- string input = Console.ReadLine();
- while (input != "Over")
- {
- string[] phones = input.Split(new[] {' ', ':'}, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string name = phones[0];
- string number = phones[1];
- bool isNumberNumber = number.All(char.IsDigit);
- bool isNumberName = name.All(char.IsDigit);
- if (!isNumberName && isNumberNumber)
- {
- phonebook[name] = long.Parse(number);
- }
- else if (isNumberName && !isNumberNumber)
- {
- phonebook[number] = long.Parse(name);
- }
- input = Console.ReadLine();
- }
- foreach (KeyValuePair<string, long> item in phonebook)
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement