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;
- //Write a program that receives some info from the console about people and their phone numbers.
- //You are free to choose the manner in which the data is entered; each entry should have just one name and one number
- //(both of them strings).
- //After filling this simple phonebook, upon receiving the command "search", your program should be able to perform
- //a search of a contact by name and print her details in format "{name} -> {number}". In case the contact isn't found, print
- //"Contact {name} does not exist."
- class Phonebook
- {
- static void Main()
- {
- Dictionary<string, string> phonebook = new Dictionary<string, string>();
- string contactName = "";
- string contactNumber = "";
- while (true)
- {
- string[] contact = Console.ReadLine().Split(new char[] { '-' }).ToArray();
- if (contact[0] != "search" && contact.Length >= 2)
- {
- contactName = contact[0];
- contactNumber = contact[1];
- phonebook.Add(contactName, contactNumber);
- }
- else
- {
- while (contact[0] == "search")
- {
- string searchName = Console.ReadLine();
- if (phonebook.ContainsKey(searchName))
- {
- Console.WriteLine("{0} -> {1}", searchName, phonebook[searchName]);
- contact[0] = "search";
- }
- else
- {
- Console.WriteLine("Contact {0} does not exist.", searchName);
- contact[0] = "search";
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement