My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest.
I am the one who establishes the list so I told him: "Don't worry any more, I will modify the order of the list". It was decided to attribute a "weight" to numbers. The weight of a number will be from now on the sum of its digits.
For example 99 will have "weight" 18, 100 will have "weight" 1 so in the list 100 will come before 99.
Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?
Example:
"56 65 74 100 99 68 86 180 90" ordered by numbers weights becomes:
"100 180 90 56 65 74 68 86 99"
When two nu

博客内容介绍了如何根据数字的权重(即数字各位之和)对数字进行排序,当权重相等时按字符串顺序排列。作者通过创建Weight类并实现IComparable接口,将输入字符串转换为Weight对象列表并调用Sort()方法进行排序。
最低0.47元/天 解锁文章
477

被折叠的 条评论
为什么被折叠?



