Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. class Program
  2. {
  3. static int[] mas = { 1321, 321, 123, 213, 231, 3121 };
  4. static int[] x = new int[mas.Length];
  5. static int[] y = new int[mas.Length];
  6. static int maxNumbers;
  7. static void Main(string[] args)
  8. {
  9. int[,] cop = new int[3, mas.Length];
  10. for (int i = 0; i < mas.Length; i++)
  11. {
  12. Preparation(cop, i);
  13. }
  14. Sort(cop);
  15. //Запись в y
  16. for (int i = 0; i < mas.Length; i++)
  17. y[i] = cop[0, i];
  18. Console.ReadKey();
  19. }
  20. private static void Preparation(int[,] cop, int i)
  21. {
  22. cop[0, i] = mas[i];
  23. cop[1, i] = mas[i] / 10;
  24. cop[2, i] = mas[i] % 10;
  25. if (mas[i].ToString().Length > maxNumbers)
  26. maxNumbers = mas[i].ToString().Length;
  27. }
  28. private static void Sort(int[,] cop)
  29. {
  30. for (int z = 0; z < maxNumbers; z++)
  31. {
  32. for (int j = 0; j < mas.Length; j++)
  33. {
  34. for (int i = 0; i < mas.Length; i++)
  35. {
  36. if (i == j)
  37. break;
  38. if (cop[2, i] < cop[2, j])
  39. {
  40. Reverse(cop, j, i);
  41. Print(cop);
  42. }
  43. if (cop[2, i] == cop[2, j])
  44. {
  45. double io = Math.Pow(10, z + 1);
  46. if (cop[0, j] % io < cop[0, i] % io)
  47. {
  48. Reverse(cop, j, i);
  49. }
  50. }
  51. }
  52. }
  53. for (int i = 0; i < mas.Length; i++)
  54. {
  55. cop[1, i] /= 10;
  56. cop[2, i] = cop[1, i] % 10;
  57. }
  58. Print(cop);
  59. }
  60. }
  61. private static void Reverse(int[,] cop, int j, int i)
  62. {
  63. int temp = cop[2, i];
  64. cop[2, i] = cop[2, j];
  65. cop[2, j] = temp;
  66. temp = cop[0, i];
  67. cop[0, i] = cop[0, j];
  68. cop[0, j] = temp;
  69. temp = cop[1, i];
  70. cop[1, i] = cop[1, j];
  71. cop[1, j] = temp;
  72. }
  73. static void Print(int[,] cop)
  74. {
  75. Console.WriteLine();
  76. for (int i = 0; i < 3; i++)
  77. {
  78. for (int j = 0; j < mas.Length; j++)
  79. {
  80. Console.Write(cop[i, j] + "\t");
  81. }
  82. Console.WriteLine();
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement