Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Phonebook2
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Dictionary<string, string> data =
- new Dictionary<string, string>();
- while (input != "END")
- {
- string[] tokens = input.Split(' ').ToArray();
- char ch = char.Parse(tokens[0]);
- if (tokens.Length == 3)
- {
- if (ch == 'A')
- {
- string name = tokens[1];
- string number = tokens[2];
- if (!data.ContainsKey(name))
- {
- data[name] = number;
- }
- data[name] = number;
- }
- }
- else if (tokens.Length == 2)
- {
- if (ch == 'S')
- {
- string name = tokens[1];
- foreach (var record in data)
- {
- if (record.Key == name)
- {
- Console.WriteLine("{0} -> {1}",record.Key,record.Value);
- }
- }
- if (!data.ContainsKey(name))
- {
- Console.WriteLine("Contact {0} does not exist.", name);
- }
- }
- }
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement