Sort by

recency

|

2709 Discussions

|

  • + 1 comment

    C# Solution

        Dictionary<string,uint> phoneList = new Dictionary<string,uint>();
    
        int entries = int.Parse(Console.ReadLine());
    
        while(entries > 0)
        {
            string[] entry = Console.ReadLine().Split();
            string name = entry[0];
            uint tel = uint.Parse(entry[1]);
    
            phoneList.Add(name, tel);
    
            entries--;
        }
    
        bool lookUp = true;
    
        while(lookUp)
        {
            string lookFor = Console.ReadLine();
    
            if(lookFor == string.Empty || lookFor == null)
            {
                lookUp = false;
            }            
            else
            {
                if(phoneList.ContainsKey(lookFor))
                {
                    Console.WriteLine("{0}={1}", lookFor, phoneList[lookFor]);
                }
                else Console.WriteLine("Not found");
            }
        }
    
    • + 1 comment

      Maybe another output option would be interesting to you.
      ...
      string query;
      while ((query = Console.ReadLine()) != null) // Read to the end. It is also suitable if the number of names being checked is unknown.
      {
      if (phoneList.TryGetValue(query, out string phone))
      Console.WriteLine($"{query}={phone}");
      else
      Console.WriteLine("Not found");
      }

      • + 0 comments

        Seems a good choice. Thanks

  • + 0 comments

    Be Aware: After the n lines of phone book entries, there are an unknown number of lines of queries.

    One of solutions: while True: try: ... except EOFError: ...

  • + 0 comments

    This is my submission in JS

    let list = input.split('\n');
        let phoneBook = {};
        const n = parseInt(list[0]);
    
    
        for (let i = 1; i <= n; i++) {
            let [name, number] = list[i].split(' ');
            phoneBook[name] = number;
        }
    
        for (let i = n + 1; i < list.length; i++) {
            let name = list[i];
            if (name in phoneBook) {
                console.log(`${name}=${phoneBook[name]}`);
            } else {
                console.log('Not found');
            }
    *     }
    
  • + 0 comments

    im failing in test case1 but passing all the other ones im about to loose it

  • + 1 comment
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    n=int(input())
    k={}
    for i in range(n):
        name,ph=input().split()
        k[name]=int(ph)
    try:
        while True:
            inp=input()
            if inp in k:
                print(f'{inp}={k[inp]}')
            else:
                print('Not found')
    except EOFError:
        pass
    
    • + 1 comment

      the logic is correct but you wont pass the test cases since u print the outcome of the search right after the user inserts the name , not after the user inserts all the names hes searching for , correct me if im wrong

      • + 0 comments

        no all test cases will be passed.... once again re check the code you will understand..... because we don't know how many inputs exist those may be many...how can you insert all in first ..😅