Sort by

recency

|

2716 Discussions

|

  • + 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")
    
  • + 0 comments

    Here's what I have for Python 3:

    import sys
    
    entries = int(input())
    friends = {}
    
    # The first n lines
    for _ in range(entries):
        name, number = input().split(' ')
        friends[name] = number
    
    # The remaining lines
    for line in sys.stdin:
        name = line.strip()
        if name in friends:
            print(f"{name}={friends.get(name)}")
        else:
            print("Not found")
    
  • + 1 comment

    code in python

    n = int(input().strip())
    my_contact = {}
    
    # Store contacts
    for _ in range(n):
        name, number = input().strip().split()
        my_contact[name.lower()] = int(number)
    
    # Search contacts until EOF (End of Input)
    try:
        while True:
            search_name = input().strip()
            key = search_name.lower()
            if key in my_contact:
                print(f"{search_name}={my_contact[key]}")
            else:
                print("Not found")
    except EOFError:
        pass
    
  • + 0 comments

    JS solution

    function processData(input) {
        //Enter your code here
        const persArray = input.split('\n'); //get lines as array
        const nPpl = Number(persArray[0]); //first input line is nPpl
        var phonebook = new Map(); 
        
        for (let i = 1; i <= nPpl; i++){
            let details = persArray[i].split(' '); //get array [name,num]
            phonebook.set(details[0],details[1])
        }
        
        for (let i = nPpl + 1; i < persArray.length; i++){
            let person = persArray[i];
            let num = phonebook.get(person);
            if (num) {
                console.log(person + '=' + num)
            } else{console.log('Not found')}
        }
    }