-
-
Save astambi/c11c4bcd6fd2d556eed4ab8e005ca943 to your computer and use it in GitHub Desktop.
Phonebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Phonebook | |
{ | |
public class Phonebook | |
{ | |
public static void Main() | |
{ | |
SortedDictionary<string, string> phonebook = new SortedDictionary<string, string>(); | |
string input = ""; | |
while ((input = Console.ReadLine()) != "END") | |
{ | |
string[] data = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | |
if (data.Length <= 1) continue; | |
string name = data[1]; | |
string phonenumber = ""; | |
switch (data[0]) | |
{ | |
case "A": | |
{ | |
if (!phonebook.ContainsKey(name)) | |
phonebook[name] = ""; | |
for (int i = 2; i < data.Length; i++) | |
phonenumber += data[i]; | |
phonebook[name] = phonenumber; | |
break; | |
} | |
case "S": | |
{ | |
if (phonebook.ContainsKey(name)) | |
Console.WriteLine(string.Join(" -> ", name, phonebook[name])); | |
else Console.WriteLine("Contact {0} does not exist.", name); | |
break; | |
} | |
default: break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment