#39 Help the bookseller ! 


A bookseller has lots of books classified in 26 categories labeled A, B, ... Z. Each book has a code of 3, 4, 5 or more capitals letters. The first letter of a letter is the capital letter of the book category. In the bookseller's stocklist each code is followed by a space and a positive integer n (int n> = 0) which indicates the quantity of books in this code in stock.


For example an extract of one of the stocklists could be:


L = {"ABART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"}.

or


L = ["ABART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"] or ....

You will be given a stocklist (L) and a list of categories in capital letters.


  M = {"A", "B", "C", "W"}

or


  M = ["A", "B", "C", "W"] or ...

and your task is to find all the books of L with codes belonging to each category.


For the lists L and M, you have to return the string (in Haskell / Clojure a list of pairs):


  (A: 20) - (B: 114) - (C: 50) - (W: 0)

"BKWRK" and "BTSQZ", 50 corresponding to "CDXEF" and 0 to category 'W', where A, B, C and W are the categories, since there is no code beginning with W.


If L or M are empty return string is "" (Clojure should return an empty array instead).


+ Recent posts