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
let me know if u find any discrepancy
Asif,
It seems that something is messed up. You didn't say how to score a suffix. If a suffix is scored with the same weight as a last name, then "William III" should score higher than 'William II' in problem 5. If the suffix is not scored at all, then 'william' should score higher than 'William II' or 'William III'. The same sort of problem occurs in problem 4.
if i remember correctly, suffix was supposed to be treated similarly to a prefix. [the 1st letter only]
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).
Looks like the "J." in "J. S. Kowontan" is treated as a prefix.
Solution Comments
Show commentsProblem Recent Solvers6
Suggested Problems
-
Program an exclusive OR operation with logical operators
716 Solvers
-
Find the "ordinary" or Euclidean distance between A and Z
161 Solvers
-
462 Solvers
-
1117 Solvers
-
484 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!