Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static int[] mas = { 1321, 321, 123, 213, 231, 3121 };
- static int[] x = new int[mas.Length];
- static int[] y = new int[mas.Length];
- static int maxNumbers;
- static void Main(string[] args)
- {
- int[,] cop = new int[3, mas.Length];
- for (int i = 0; i < mas.Length; i++)
- {
- Preparation(cop, i);
- }
- Sort(cop);
- //Запись в y
- for (int i = 0; i < mas.Length; i++)
- y[i] = cop[0, i];
- Console.ReadKey();
- }
- private static void Preparation(int[,] cop, int i)
- {
- cop[0, i] = mas[i];
- cop[1, i] = mas[i] / 10;
- cop[2, i] = mas[i] % 10;
- if (mas[i].ToString().Length > maxNumbers)
- maxNumbers = mas[i].ToString().Length;
- }
- private static void Sort(int[,] cop)
- {
- for (int z = 0; z < maxNumbers; z++)
- {
- for (int j = 0; j < mas.Length; j++)
- {
- for (int i = 0; i < mas.Length; i++)
- {
- if (i == j)
- break;
- if (cop[2, i] < cop[2, j])
- {
- Reverse(cop, j, i);
- Print(cop);
- }
- if (cop[2, i] == cop[2, j])
- {
- double io = Math.Pow(10, z + 1);
- if (cop[0, j] % io < cop[0, i] % io)
- {
- Reverse(cop, j, i);
- }
- }
- }
- }
- for (int i = 0; i < mas.Length; i++)
- {
- cop[1, i] /= 10;
- cop[2, i] = cop[1, i] % 10;
- }
- Print(cop);
- }
- }
- private static void Reverse(int[,] cop, int j, int i)
- {
- int temp = cop[2, i];
- cop[2, i] = cop[2, j];
- cop[2, j] = temp;
- temp = cop[0, i];
- cop[0, i] = cop[0, j];
- cop[0, j] = temp;
- temp = cop[1, i];
- cop[1, i] = cop[1, j];
- cop[1, j] = temp;
- }
- static void Print(int[,] cop)
- {
- Console.WriteLine();
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < mas.Length; j++)
- {
- Console.Write(cop[i, j] + "\t");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement