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");
            }
        }
    
  • + 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