You are viewing a single comment's thread. Return to all comments →
import java.util.Scanner; class Search { public static void main(String ar[]) { int n,i; Scanner in=new Scanner(System.in); n=in.nextInt(); String name[]=new String[n]; int phone[]=new int[n]; for(i=0;i<n;i++){ name[i]=in.next(); phone[i]=in.nextInt(); } while(in.hasNext()){ int f=0; String s=in.next(); for(i=0;i<n;i++) { if(s.compareTo(name[i])==0){ f=1; break;} } if(f==1) System.out.println(name[i]+"="+phone[i]); else System.out.println("Not found"); } } }
My code was terminated due to time out. Couldn't pass the test case 1,2,3. Somebody just help me out.
Seems like cookies are disabled on this browser, please enable them to open this website
Day 8: Dictionaries and Maps
You are viewing a single comment's thread. Return to all comments →
My code was terminated due to time out. Couldn't pass the test case 1,2,3. Somebody just help me out.