Created
June 2, 2019 22:28
-
-
Save brianmed/4b2bdb7185b048c5e067d0cfc4324411 to your computer and use it in GitHub Desktop.
LexicographSort Integer List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| namespace LexicographicSortIntegerList | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // echo "41 4\n" | dotnet run (Output 441) | |
| List<int> digits = Console.ReadLine() | |
| .Split(' ') | |
| .Select(x => Int32.Parse(x)) | |
| .ToList(); | |
| digits.Sort((a, b) => { | |
| int left = Int32.Parse(a.ToString() + b.ToString()); | |
| int right = Int32.Parse(b.ToString() + a.ToString()); | |
| return right.CompareTo(left); | |
| }); | |
| Console.WriteLine(String.Join("", digits)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment