Cody

Problem 65. Word Counting and Indexing

Solution 1743870

Submitted on 6 Mar 2019 by danteliujie
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
sl = {'one two three','two one four zero'}; wtc = {'four','one','three','two','zero'}; silc = {[2 4 3],[4 2 1 5]}; [wt,sil] = word_index(sl); assert(isequal(wt,wtc))

str_list = 1×2 cell array {'one two three'} {'two one four zero'} str_index_list = 0×0 empty cell array ia = 2 3 4 ib = 1 3 2 str_index_list = 1×1 cell array {1×3 double} ia = 1 2 4 5 ib = 3 2 1 4 str_index_list = 1×2 cell array {1×3 double} {1×4 double}

2   Pass
sl = {'one two three'}; wtc = {'one','three','two'}; silc = {[1 3 2]}; [wt,sil] = word_index(sl); assert(isequal(wt,wtc))

str_list = 1×1 cell array {'one two three'} str_index_list = 0×0 empty cell array ia = 1 2 3 ib = 1 3 2 str_index_list = 1×1 cell array {1×3 double}

3   Pass
sl = {'this little piggy went to market', ... 'and this little piggy stayed home', ... 'this little piggy had roast beef', ... 'and this one studied computer science at piggy university'}; wtc = { ... 'and','at','beef','computer','had','home', ... 'little','market','one','piggy','roast','science', ... 'stayed','studied','this','to','university','went'}; silc = { ... [15 7 10 18 16 8], ... [1 15 7 10 13 6], ... [15 7 10 5 11 3], ... [ 1 15 9 14 4 12 2 10 17]}; [wt,sil] = word_index(sl); assert(isequal(wt,wtc))

str_list = 1×4 cell array {'this little piggy went to market'} {'this little piggy had roast beef'} {'and this little piggy stayed home'} {'and this one studied computer scien…'} str_index_list = 0×0 empty cell array ia = 7 8 10 15 16 18 ib = 2 6 3 1 5 4 str_index_list = 1×1 cell array {1×6 double} ia = 3 5 7 10 11 15 ib = 6 4 2 3 5 1 str_index_list = 1×2 cell array {1×6 double} {1×6 double} ia = 1 6 7 10 13 15 ib = 1 6 3 4 5 2 str_index_list = 1×3 cell array {1×6 double} {1×6 double} {1×6 double} ia = 1 2 4 9 10 12 14 15 17 ib = 1 7 5 3 8 6 4 2 9 str_index_list = 1×4 cell array {1×6 double} {1×6 double} {1×6 double} {1×9 double}