Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Record
- {
- public int weight;
- public string number;
- public Record(int weight, string number)
- {
- this.weight = weight;
- this.number = number;
- }
- }
- public class WeightSort
- {
- public static string orderWeight(string strng)
- {
- var numbers = strng.Split(' ');
- List<Record> weightList = new List<Record>();
- foreach(string num in numbers)
- {
- int x = 0;
- foreach (char n in num)
- {
- x += (int)char.GetNumericValue(n);
- }
- weightList.Add( new Record (x, num));
- }
- var result = String.Join(" ", weightList.OrderBy(a => a.weight).ThenBy(a => a.number).Select(b=>b.number).ToArray());
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement