Problem 70. Alphabetize by last name
Given a list of names in a cell array, sort the list by the last name. So if
list = {'Barney Google','Snuffy Smith','Dagwood Bumstead'};
then the output is
alpha_list = {'Dagwood Bumstead','Barney Google','Snuffy Smith'}
Solution Stats
Problem Comments
-
6 Comments
looks like there is problem with the 2nd test case result. The 'Cleve Molar' is shifted by 1 space in the ans
This problem can be trickier if the input can allow different styles of name representation, e.g., 'FirstName LastName' and 'LastName, FirstName'.
be careful with 'John F. Kennedy' case..
The change in output format was a pain !
This blew my mind. Finally got it.
Be careful with output format...
if length(alpha_list) > 5
alpha_list = alpha_list';
end
Solution Comments
Show commentsProblem Recent Solvers2248
Suggested Problems
-
Calculate the Levenshtein distance between two strings
1425 Solvers
-
Project Euler: Problem 4, Palindromic numbers
1042 Solvers
-
684 Solvers
-
Create an index-powered vector
769 Solvers
-
Pernicious Anniversary Problem
821 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!