SHARE
TWEET

Untitled

a guest Sep 15th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Record
  6.     {
  7.         public int weight;
  8.         public string number;
  9.         public Record(int weight, string number)
  10.         {
  11.             this.weight = weight;
  12.             this.number = number;
  13.         }
  14.     }
  15.  
  16.     public class WeightSort
  17.     {
  18.         public static string orderWeight(string strng)
  19.         {
  20.             var numbers = strng.Split(' ');
  21.             List<Record> weightList = new List<Record>();
  22.  
  23.             foreach(string num in numbers)
  24.             {
  25.                 int x = 0;
  26.                 foreach (char n in num)
  27.                 {
  28.                    x += (int)char.GetNumericValue(n);  
  29.                 }
  30.  
  31.                 weightList.Add( new Record (x, num));
  32.             }
  33.  
  34.             var result = String.Join(" ", weightList.OrderBy(a => a.weight).ThenBy(a => a.number).Select(b=>b.number).ToArray());
  35.             return result;
  36.         }
  37.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top