Sort by

recency

|

2703 Discussions

|

  • + 0 comments

    I am facing a runtime issue in test case 1 in the following code (most probably due to time limit)

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    number_of_entries = int(input())
    Name_phone_number_dict = {}
    
    for _ in range(number_of_entries):
        input_split = input().split(' ')
        Name_phone_number_dict[input_split[0]] = input_split[1]
    for _ in range(number_of_entries):
        name_check = input()
        if name_check in Name_phone_number_dict:
            print(name_check+"="+Name_phone_number_dict[name_check])
        else:
            print("Not found")
    

    How to tackle this, is there any better way to do this in python.

    `

  • + 1 comment

    """ This is my submission in Python, it's not runnning within time limits, can someone help? """

    import re

    phoneBook = {} if name == 'main': n = int(input().strip()) for i in range(n): match = re.match(r'(\w+)\s+(\d+)', input().strip()) phoneBook[match.group(1)] = match.group(2)

    def queryPhoneBook(name): if name in list(phoneBook.keys()): print(f'{name}={phoneBook[name]}') else: print('Not found')

    try: go = True while go: q = input().strip() if len(q)>0: queryPhoneBook(q) else: break except EOFError: pass

  • + 0 comments
    import java.util.*;
    import java.io.*;
    
    class Solution{
        public static void main(String []argh){
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            Map<String, Integer> phone_book = new HashMap<>();
            int get_phone;
            for(int i = 0; i < n; i++){
                String name = in.next();
                int phone = in.nextInt();
                phone_book.put(name, phone);
            }
            while(in.hasNext()){
                String s = in.next();
                if(phone_book.containsKey(s)){
    						    get_phone = phone_book.get(s);
                    System.out.println(s + "=" + get_phone);
                } else {
                    System.out.println("Not found");
                }
            }
            in.close();
        }
    }
    
  • + 0 comments

    n = int(input())

    phone_book = {}

    for _ in range(n): entry = input().split() name = entry[0] phone_number = entry[1] phone_book[name] = phone_number

    try: while True: query = input().strip() if query in phone_book: print(f"{query}={phone_book[query]}") else: print("Not found") except EOFError: pass

  • + 1 comment

    Im new in c++, and met a problem in test case 1, and I don't know where the problem is. Does anyone know the problem? Here's the code:

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <map>
    using namespace std;
    
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int n;
        cin >> n;
        map<string, string> phone;
        
        for (int i=0;i<n;i++){
            string name_temp;
            string phone_temp;
            cin >> name_temp >> phone_temp;
            phone.insert(pair<string, string>(name_temp,phone_temp));
        }
        for (int i=0;i<n;i++){
            string query_temp;
            string out_temp;
            cin >> query_temp;
            map<string, string>::iterator it= phone.find(query_temp);
            if (it!=phone.end()){
                out_temp = it->second;
                cout << query_temp << "=" << out_temp <<endl;
            } else { cout << "Not found" << endl;}
            
        }
        
        return 0;
    }