Bloomberg Laundry Day - count items in list, check socks for pairs, and organize all items alphabetically
3 Репутация автора
I'm trying to solve the following problem: https://codecon.bloomberg.com/challenger-series/33
Each article of clothing will have its own separate line. You have a penchant for hoarding, so there is no guarantee as to the number of pieces, but you can assure yourself that each article can be easily categorized by description (name).
Articles of clothing will be fed in as line-delimited list. See below for examples.
Output should be an alphabetically (case-insensitive) sorted, line-delimited list of the articles of clothing along with their count. Each field (count, category) should be separated by a pipe (|). If you come across a sock without a soulmate, the count should be designated by a 0 (zero). Socks that are in pairs should be on separate lines from the socks of the same category without pairs, and should come before the pairless sock. See below for examples.
white shirt polka dot sock red sock superhero shirt torn jeans polka dot sock white shirt polka dot sock
1|polka dot sock 0|polka dot sock 0|red sock 1|superhero shirt 1|torn jeans 2|white shirt
My attempt at a solution (https://codereview.stackexchange.com/questions/179931/bloomberg-laundry-day-count-items-in-list-check-socks-for-pairs-and-organize) is passing the sample test case (above) but failing secret test cases.
So, I'm wondering what extra information I should be extracting from the input and output specifications? For example, I'm storing my clothing and the associated counts in a TreeMap, but I first convert the clothing description into small caps, because I figure that a White Shirt is the same thing as a white shirt. But I've tried other things - I've tried (a) storing the original string and using CASE_INSENSITIVE_ORDER for my tree map, and (b) storing the original strings and the counts for those strings in a HashMap, and storing all unique original strings in an ArrayList, then sorting all the original strings by CASE_INSENSITIVE_ORDER at the end, then using this order to print the results. Each of these attempts succeeds on the sample test case and fails some secret test.
How can I write useful tests for this? I've tried the corner case of an empty input, and my program works as expected. What else can I look out for?Автор: ArbitraryGenera Источник Размещён: 08.11.2017 10:08
555 Репутация автора
in your example code:
String clothingItem = stdin.nextLine().toLowerCase(); incrementCount(clothingCount, clothingItem);
it looks like your storing the lowercase string, and not the original string. Question asks for original string, SORTED as if it were case insensitive.Автор: NikT Размещён: 22.11.2017 05:02