Cody

Problem 70. Alphabetize by last name

Solution 2616313

Submitted on 26 Jun 2020 by 春樹 内糸
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

alpha_list = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Snuffy Smith'} last = [] fl = 1×2 cell array {'Barney'} {'Google'} last = "Google" fl = 1×2 cell array {'Snuffy'} {'Smith'} last = 1×2 string array "Google" "Smith" fl = 1×2 cell array {'Dagwood'} {'Bumstead'} last = 1×3 string array "Google" "Smith" "Bumstead" idx = 3 1 2 alpha_list = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Snuffy Smith'}

2   Pass
list = {'Harry Truman' 'Dwight Eisenhower' 'John F. Kennedy' 'Lyndon Johnson' 'Richard Nixon' 'Gerald Ford' 'Cleve Moler' 'Ronald Reagan' 'George Bush' 'Bill Clinton' 'George Bush' 'Barack Obama'}; alpha_list = {'George Bush' 'George Bush' 'Bill Clinton' 'Dwight Eisenhower' 'Gerald Ford' 'Lyndon Johnson' 'John F. Kennedy' 'Cleve Moler' 'Richard Nixon' 'Barack Obama' 'Ronald Reagan' 'Harry Truman'} assert(isequal(alphabetize(list),alpha_list))

alpha_list = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Richard Nixon' } {'Barack Obama' } {'Ronald Reagan' } {'Harry Truman' } last = [] fl = 1×2 cell array {'Harry'} {'Truman'} last = "Truman" fl = 1×2 cell array {'Dwight'} {'Eisenhower'} last = 1×2 string array "Truman" "Eisenhower" fl = 1×3 cell array {'John'} {'F.'} {'Kennedy'} last = 1×3 string array "Truman" "Eisenhower" "Kennedy" fl = 1×2 cell array {'Lyndon'} {'Johnson'} last = 1×4 string array "Truman" "Eisenhower" "Kennedy" "Johnson" fl = 1×2 cell array {'Richard'} {'Nixon'} last = 1×5 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" fl = 1×2 cell array {'Gerald'} {'Ford'} last = 1×6 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" "Ford" fl = 1×2 cell array {'Cleve'} {'Moler'} last = 1×7 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" "Ford" "Moler" fl = 1×2 cell array {'Ronald'} {'Reagan'} last = 1×8 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" "Ford" "Moler" "Reagan" fl = 1×2 cell array {'George'} {'Bush'} last = 1×9 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" "Ford" "Moler" "Reagan" "Bush" fl = 1×2 cell array {'Bill'} {'Clinton'} last = 1×10 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" "Ford" "Moler" "Reagan" "Bush" "Clinton" fl = 1×2 cell array {'George'} {'Bush'} last = 1×11 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" "Ford" "Moler" "Reagan" "Bush" "Clinton" "Bush" fl = 1×2 cell array {'Barack'} {'Obama'} last = 1×12 string array "Truman" "Eisenhower" "Kennedy" "Johnson" "Nixon" "Ford" "Moler" "Reagan" "Bush" "Clinton" "Bush" "Obama" idx = 9 11 10 2 6 4 3 7 5 12 8 1 alpha_list = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Richard Nixon' } {'Barack Obama' } {'Ronald Reagan' } {'Harry Truman' }

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!