using System using System Collections Generic using System Linq using

 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
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlockSort
{
class Program
{
public class IJ
{
public int[] I, J, S;
public IJ(int digital)
{
this.I = new int[digital];
this.J = new int[digital];
this.S = new int[digital + 1];
for (int i = 0; i < digital; ++i)
{
this.S[i] = 0;
}
}
}
static void Main(string[] args)
{
int[,] input = new int[1, 2] { { 7, 4 }, { 0, 1 }, { 6, 3 }, { 5, 5 }, { 4, 7 }, { 1, 2 } };
int n = 5, m = 6;
IJ sort = new IJ(m);
for (int i = 0; i < m; ++i)
{
sort.I[i] = input[i, 0];
sort.J[i] = input[i, 1];
}
for (int i = 0; i < m; ++i)
{
sort.S[lol.I[i] + 1]++;
}
for (int i = 1; i <= n; ++i)
{
sort.S[i] += sort.S[i - 1];
}
Console.WriteLine("I J");
for (int i = 0; i < m; ++i)
{
Console.WriteLine(sort.I[i] + " " + sort.J[i]);
}
for (int i = 0; i < n; ++i)
{
while (i < sort.S[sort.I[i]])
{
int i0 = sort.I[i], j0 = sort.J[i];
lol.I[i] = sort.I[sort.S[i0]];
lol.J[i] = lol.J[sort.S[i0]];
lol.I[sort.S[i0]] = i0;
lol.J[sort.S[i0]] = j0;
if (i >= sort.S[sort.I[i]])
{
sort.S[i]++;
i++;
}
}
}
Console.WriteLine();
Console.WriteLine("I J");
for (int i = 0; i < m; ++i)
{
Console.WriteLine(sort.I[i] + " " + sort.J[i]);
}
}
}
}