Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _07b_Dictionaries_Lambda_Expressions_LINQ_Exercises
- {
- class Dictionaries_Lambda_Expressions_LINQ_Exercises
- {
- static void Main(string[] args)
- {
- List<string> commands = Console.ReadLine().Split().ToList();
- Dictionary<string, string> contacts = new Dictionary<string, string>();
- while (commands[0] != "END")
- {
- if (commands[0] == "A")
- {
- if (contacts.ContainsKey(commands[1]))
- {
- contacts[commands[1]] = commands[2];
- }
- else
- {
- contacts.Add(commands[1], commands[2]);
- }
- }
- else if (commands[0] == "S")
- {
- if (contacts.ContainsKey(commands[1]))
- {
- Console.WriteLine($"{commands[1]} -> {contacts[commands[1]]}");
- }
- else
- {
- Console.WriteLine($"Contact {commands[1]} does not exist.");
- }
- }
- commands = Console.ReadLine().Split().ToList();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment