-
Notifications
You must be signed in to change notification settings - Fork 0
/
Big Sorting.cs
67 lines (65 loc) · 1.63 KB
/
Big Sorting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
/*Sample Input 0:
* 6
* 31415926535897932384626433832795
* 1
* 3
* 10
* 3
* 5
* Sample Output 0:
* 1
* 3
* 3
* 5
* 10
* 31415926535897932384626433832795
*/
namespace Sorting
{
/// <summary>
/// Big sorting
/// https://www.hackerrank.com/challenges/big-sorting
/// Thanks: Sung kim (dance2 die) Lakshmikant deshpande (lakshmikantd)
/// </summary>
public class BigIntegerCustomCompare : IComparer<string>
{
public int Compare(string x, string y)
{
if ( x.Length > y.Length )
return 1;
else if ( x.Length < y.Length )
return -1;
else
{
for (int i = 0; i < x.Length; i++)
{
if (Convert.ToInt32(x[i]) > Convert.ToInt32(y[i]))
return 1;
if (Convert.ToInt32(x[i]) < Convert.ToInt32(y[i]))
return -1;
}
}
return 0;
}
}
class Big_Sorting
{
public static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
string[] arrString = new string[size];
for ( int i = 0; i < size; i++ )
{
arrString[i] = Console.ReadLine();
}
Array.Sort(arrString, new BigIntegerCustomCompare());
foreach (string value in arrString)
{
Console.WriteLine(value);
}
Console.ReadKey();
}
}
}