Program.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. class Programm
  2. {
  3. static int[,] pruff;
  4. class pruf
  5. {
  6. static void Main()
  7. {
  8. int k = 0;
  9. using(StreamReader reader = new StreamReader("pruf.txt"))
  10. {
  11. string massiv = reader.ReadLine();
  12. while(massiv != null)
  13. {
  14. k++;
  15. massiv = reader.ReadLine();
  16. }
  17. pruff = new int[k, 2];
  18. }
  19. using (StreamReader reader = new StreamReader("pruf.txt"))
  20. {
  21. string massiv = reader.ReadLine();
  22. int l = 0;
  23. while (massiv != null)
  24. {
  25. string[] rebra = new string[2];
  26. rebra = massiv.Split(' ').ToArray();
  27. pruff[l, 0] = Convert.ToInt32(rebra[0]);
  28. pruff[l, 1] = Convert.ToInt32(rebra[1]);
  29. l++;
  30. massiv = reader.ReadLine();
  31. }
  32. }
  33. pruferr(pruff, k);
  34. }
  35. static void pruferr(int[,] prufer, int k)
  36. {
  37. string kod = " ";
  38. int a = 0;
  39. while (a != k - 1)
  40. {
  41. int flag = 0;
  42. int min = int.MaxValue;
  43. int stroka = 0;
  44. for (int i = 0; i < prufer.GetLength(0); i++)
  45. {
  46. flag = 0;
  47. for (int j = 1; j < 2; j++)
  48. {
  49. if (prufer[i,j] < min && prufer[i,j] != 0 && flag == 0)
  50. {
  51. min = prufer[i,j];
  52. stroka = i;
  53. for(int x = 0; x< prufer.GetLength(0); x++)
  54. {
  55. for(int y = 0; y < 1; y++)
  56. {
  57. if(min == prufer[x,y])
  58. {
  59. min = int.MaxValue;
  60. flag = 1;
  61. }
  62. }
  63. }
  64. }
  65. }
  66. if (i == prufer.GetLength(0) - 1)
  67. {
  68. if (flag == 0)
  69. {
  70. min = prufer[stroka, 0];
  71. if (a == k - 2)
  72. {
  73. kod = kod + min;
  74. }
  75. else
  76. {
  77. kod = kod + min + " ";
  78. }
  79. prufer[stroka, 0] = 0;
  80. prufer[stroka, 1] = 0;
  81. a++;
  82. }
  83. }
  84. }
  85. }
  86. Console.WriteLine(kod);
  87. }
  88. }
  89. }