123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- class Programm
- {
- static int[,] pruff;
- class pruf
- {
- static void Main()
- {
- int k = 0;
- using(StreamReader reader = new StreamReader("pruf.txt"))
- {
- string massiv = reader.ReadLine();
- while(massiv != null)
- {
- k++;
- massiv = reader.ReadLine();
- }
- pruff = new int[k, 2];
- }
- using (StreamReader reader = new StreamReader("pruf.txt"))
- {
- string massiv = reader.ReadLine();
- int l = 0;
- while (massiv != null)
- {
- string[] rebra = new string[2];
- rebra = massiv.Split(' ').ToArray();
- pruff[l, 0] = Convert.ToInt32(rebra[0]);
- pruff[l, 1] = Convert.ToInt32(rebra[1]);
- l++;
- massiv = reader.ReadLine();
- }
- }
- pruferr(pruff, k);
- }
- static void pruferr(int[,] prufer, int k)
- {
- string kod = " ";
- int a = 0;
- while (a != k - 1)
- {
- int flag = 0;
- int min = int.MaxValue;
- int stroka = 0;
- for (int i = 0; i < prufer.GetLength(0); i++)
- {
- flag = 0;
- for (int j = 1; j < 2; j++)
- {
- if (prufer[i,j] < min && prufer[i,j] != 0 && flag == 0)
- {
- min = prufer[i,j];
- stroka = i;
- for(int x = 0; x< prufer.GetLength(0); x++)
- {
- for(int y = 0; y < 1; y++)
- {
- if(min == prufer[x,y])
- {
- min = int.MaxValue;
- flag = 1;
- }
- }
- }
- }
- }
- if (i == prufer.GetLength(0) - 1)
- {
- if (flag == 0)
- {
- min = prufer[stroka, 0];
- if (a == k - 2)
- {
- kod = kod + min;
- }
- else
- {
- kod = kod + min + " ";
- }
- prufer[stroka, 0] = 0;
- prufer[stroka, 1] = 0;
- a++;
- }
- }
- }
- }
- Console.WriteLine(kod);
- }
- }
- }
|