Cody

# Problem 65. Word Counting and Indexing

Solution 1892676

Submitted on 6 Aug 2019 by liu xinyang
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 = 2×1 cell array {'one two three' } {'two one four zero'} word_table = 1×5 cell array {'four'} {'one'} {'three'} {'two'} {'zero'} temp = [] words = 1×3 cell array {'one'} {'two'} {'three'} temp = 2 temp = 2 4 temp = 2 4 3 str_index_list = 1×1 cell array {1×3 double} temp = [] words = 1×4 cell array {'two'} {'one'} {'four'} {'zero'} temp = 4 temp = 4 2 temp = 4 2 1 temp = 4 2 1 5 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'} word_table = 1×3 cell array {'one'} {'three'} {'two'} temp = [] words = 1×3 cell array {'one'} {'two'} {'three'} temp = 1 temp = 1 3 temp = 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 = 4×1 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 science at piggy university'} word_table = 1×18 cell array Columns 1 through 14 {'and'} {'at'} {'beef'} {'computer'} {'had'} {'home'} {'little'} {'market'} {'one'} {'piggy'} {'roast'} {'science'} {'stayed'} {'studied'} Columns 15 through 18 {'this'} {'to'} {'university'} {'went'} temp = [] words = 1×6 cell array {'this'} {'little'} {'piggy'} {'went'} {'to'} {'market'} temp = 15 temp = 15 7 temp = 15 7 10 temp = 15 7 10 18 temp = 15 7 10 18 16 temp = 15 7 10 18 16 8 str_index_list = 1×1 cell array {1×6 double} temp = [] words = 1×6 cell array {'this'} {'little'} {'piggy'} {'had'} {'roast'} {'beef'} temp = 15 temp = 15 7 temp = 15 7 10 temp = 15 7 10 5 temp = 15 7 10 5 11 temp = 15 7 10 5 11 3 str_index_list = 1×2 cell array {1×6 double} {1×6 double} temp = [] words = 1×6 cell array {'and'} {'this'} {'little'} {'piggy'} {'stayed'} {'home'} temp = 1 temp = 1 15 temp = 1 15 7 temp = 1 15 7 10 temp = 1 15 7 10 13 temp = 1 15 7 10 13 6 str_index_list = 1×3 cell array {1×6 double} {1×6 double} {1×6 double} temp = [] words = 1×9 cell array {'and'} {'this'} {'one'} {'studied'} {'computer'} {'science'} {'at'} {'piggy'} {'university'} temp = 1 temp = 1 15 temp = 1 15 9 temp = 1 15 9 14 temp = 1 15 9 14 4 temp = 1 15 9 14 4 12 temp = 1 15 9 14 4 12 2 temp = 1 15 9 14 4 12 2 10 temp = 1 15 9 14 4 12 2 10 17 str_index_list = 1×4 cell array {1×6 double} {1×6 double} {1×6 double} {1×9 double}