Problem 45434. Weighted Names
A cell is given which contains several names. You've to return those names sorted by their weight.
Weight is to be calculated by the following rules -
1.each letter's weight is the ASCII value.
2.the 1st name weights 2 times its original value but if the name contains any middle name then the middle name would weight 2x while 1st name would weight 3x. The family name will always weight 1x.
3. Some of the names might contain some prefix like Col, Prof, Hon etc. They would weight 10 times their 1st letter. [each letter is not to be weighted for this case] 4. Again some of the names might also contain some suffix.
For example,
Ser Arthur Dayne
Here, 'Ser' is a prefix. so value = 83*10 = 830. [ASCII value of 'S' is 83] 'Dayne' is the family name. so value = 497*1 = 497 'Arthur' is the 1st name. so value = 630*2 = 1260 So total value= 830 + 497 + 1260 = 2587.
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Asif Newaz
on 6 Jun 2020
if i remember correctly, suffix was supposed to be treated similarly to a prefix. [the 1st letter only]
Rafael S.T. Vieira
on 5 Nov 2020
I can confirm it. For suffixes, just the first letter counts. If it didn't william would be greater than William, since w > W (ASCII value).
ChrisR
on 30 May 2022
Looks like the "J." in "J. S. Kowontan" is treated as a prefix.
Solution Comments
Show commentsProblem Recent Solvers6
Suggested Problems
-
304 Solvers
-
494 Solvers
-
507 Solvers
-
990 Solvers
-
Delete blanks at the end of string
79 Solvers
More from this Author165
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!