You are viewing a single comment's thread. Return to all comments →
It gave me headaches, but finally got it to work: C# implementation:
class Solution { static void Main(String[] args) { int N = Convert.ToInt32(Console.ReadLine()); Dictionary<string, int> phoneBook = new Dictionary<string, int>(N); for (int i = 0; i < N; i++) { string[] temp = Console.ReadLine().Split(' '); if (temp[1].Length == 8) { phoneBook.Add(temp[0], Convert.ToInt32(temp[1])); } } string nameToSearch = ""; while ((nameToSearch = Console.ReadLine()) != null) { int flagFound = 0; if (nameToSearch != "") { if (phoneBook.ContainsKey(nameToSearch)) { flagFound = 1; } } if (flagFound == 1) { Console.WriteLine(nameToSearch + "=" + phoneBook[nameToSearch]); } else { Console.WriteLine("Not found"); } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 8: Dictionaries and Maps
You are viewing a single comment's thread. Return to all comments →
It gave me headaches, but finally got it to work:
C# implementation: