Since the size of array is very less I think Hashmap is the best. 
Use name as the hash key and number as its value.

On Thursday, June 14, 2012 6:46:34 PM UTC+5:30, utsav sharma wrote:
>
> it can be done using map in c++
>
> On Thu, Jun 14, 2012 at 4:23 PM, Mohit Rathi <mohit08...@iiitd.ac.in>wrote:
>
>> arr1 = [abc,xyz,lmn,def]
>> arr2 = [3,6,2,8]
>>
>> if user enters "xyz" then 6 will be printed
>> else 
>> if xyz doesn't exist in arr1 then ask for a number and add them in 
>> respective arrays(name in arr1 and number in arr2).
>>
>> Hope it helps
>>
>>
>> On Thu, Jun 14, 2012 at 3:58 PM, utsav sharma 
>> <utsav.sharm...@gmail.com>wrote:
>>
>>> example pls... 
>>>
>>> On Thu, Jun 14, 2012 at 1:01 PM, Mohit Rathi <mohit08...@iiitd.ac.in>wrote:
>>>
>>>> Hi,
>>>>
>>>> *There are two arrays of length 100 each. Each of these has initially 
>>>> n (n<=100)
>>>> elements. First array contains names and the second array contains 
>>>> numbers
>>>> such that ith name in array1 corresponds to ith number in array2.
>>>> Write a program which asks the user to enter a name, finds it in array1,
>>>> *
>>>>
>>>> *a. if it exists, then print the corresponding number in array2,
>>>> b. else ask the user to input its associated number and add the number 
>>>> and
>>>> name to array2 and array1 respectively, and update the size of list*
>>>>
>>>> I can think of solving it through linear walk to the array. Anyone with 
>>>> more optimized algorithm like BST or HashTable? 
>>>>
>>>> comments are welcome
>>>>
>>>>
>>>> Thanks
>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to 
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at 
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Utsav Sharma,
>>> NIT Allahabad
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at 
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> -- 
>> Mohit Rathi
>> 4th year, B.Tech (IT)
>> IIIT-Delhi
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> -- 
> Utsav Sharma,
> NIT Allahabad
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/wF1ZUNLZV4UJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to