Sort by

recency

|

2719 Discussions

|

  • + 0 comments

    public static void main(String []argh){ Scanner in = new Scanner(System.in); int n = in.nextInt(); Map phonebook=new HashMap<>(); for(int i = 0; i < n; i++){ String name = in.next(); int phone = in.nextInt(); phonebook.put(name,phone); // Write code here } while(in.hasNext()){ String s = in.next(); //write your code here if(phonebook.containsKey(s)) System.out.println(s+"="+phonebook.get(s)); else System.out.println("Not found"); } in.close(); }

  • + 0 comments
    x = int(input())
    dic = {}
    

    Reading phonebook entries

    for i in range(x):
        a = input().split(' ', 1)
        dic[a[0]] = a[1]
    

    Handling multiple queries safely until EOF

    try: 
        while True:
            a = input()
            if len(a) > 0:
                if a in dic:
                    print(f'{a}={dic[a]}')
                else:
                    print('Not found')
    except EOFError:
        pass
    
  • + 0 comments

    This is python solution can any one fix the error it failed test case1 n= int(input()) phonebook = {} for i in range(n):

    entry = input().split()
    name = entry[0]
    phone = entry [1]
    phonebook[name] = phone
    

    queries = []

    for i in range(n): query = input() queries.append(query)

    for query in queries: if query in phonebook: print(f"{query}={phonebook[query]}")

      else:
            print("Not found")
    
  • + 1 comment

    Has anyone else had problems with test case 1 with C++? In the other test cases my code is fine

    This is my code in case someone tells me my error.

    int main() {
        map<string, string> mapa;
        string name, phone;
        int temp;
        
        cin >> temp;
        
        for (int i = 0; i < temp; i++) {
            cin >> name >> phone;
            
            mapa[name] = phone;
        }
         
        for (int i = 0; i < temp; i++) {
            cin >> name;
            
            if ( mapa.find(name) != mapa.end() ) {
                cout << name << "=" << mapa[name] << endl;
            } else {
                cout << "Not found\n";
            }
        } 
         
        return 0;
    }
    
  • + 0 comments

    Any toughts on why all the tests are Passed but getting Runtime error?

    if __name__ == '__main__':
        n = int(input())
    my_dict = {}
    for _ in range(n*2):
        s = str(input())
        if " " in s:
            nameAndPhone = s.split(" ")
            name = nameAndPhone[0]
            phone = nameAndPhone[1]
            my_dict[name] = phone
        else:
            if s in my_dict:
                print(f"{s}={my_dict[s]}")
            else:
                print("Not found")