Skip to content

Instantly share code, notes, and snippets.

@astambi
Created September 11, 2016 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astambi/c11c4bcd6fd2d556eed4ab8e005ca943 to your computer and use it in GitHub Desktop.
Save astambi/c11c4bcd6fd2d556eed4ab8e005ca943 to your computer and use it in GitHub Desktop.
Phonebook
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