Exemple #1
0
    static void Main()
    {
        double count;

        Console.WriteLine("Введите кол-во палат в больнице");
        int n = Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("Введите кол-во коек в каждой палате");
        int m = Convert.ToInt32(Console.ReadLine());

        double[,] hosp = new double[n, m];
        for (int i = 0; i < hosp.GetLength(0); i++)
        {
            for (int j = 0; j < hosp.GetLength(1); j++)
            {
                Console.WriteLine("Введите температуру пациента, находящегося на койке {0}  в палате {1}", j + 1, i + 1);
                count      = Convert.ToDouble(Console.ReadLine());
                hosp[i, j] = count;
            }
        }
        Console.WriteLine("Обычная реализация:\n");
        SolvingTaskMassive.SimpleMassiveObjective(hosp);
        Console.WriteLine("\n\nУпрощенная реализация с использованием Array:\n");
        SolvingTaskMassive.ArrayObjective(hosp);
    }
    static void Main()
    {
        unsafe
        {
            int rows    = 10,
                columns = 4;

            int *ptr = stackalloc int[rows * columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    ptr[i * columns + j] = rows;
                }
            }
            int counter = default(int);
            for (int i = 0; i < rows; i++)
            {
                Console.WriteLine("В палате {0} находится {1} коек(и).\n", i + 1, rows);
                for (int j = 0; j < columns; j++)
                {
                    if (ptr[i * columns + j] != 0 || ptr[i * columns + j] > 0)
                    {
                        counter++;
                        Console.WriteLine("В койке {0} лежит пациент с температурой {1}", j + 1, ptr[i * columns + j]);
                    }
                }
            }
            //
            double count;
            Console.WriteLine("Введите кол-во палат в больнице");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Введите кол-во коек в каждой палате");
            int     m    = Convert.ToInt32(Console.ReadLine());
            double *hosp = stackalloc double[n * m];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    Console.WriteLine("Введите температуру пациента, находящегося на койке {0}  в палате {1}", j + 1, i + 1);
                    count           = Convert.ToDouble(Console.ReadLine());
                    hosp[i * m + j] = count;
                }
            }
            Console.WriteLine("Обычная реализация:\n");
            SolvingTaskMassive.SimpleMassiveObjective(hosp, n, m);
        }
    }
    unsafe static public void SimpleMassiveObjective(double *hospital, int rows, int columns)
    {
        bool is_exist = false;

        Console.WriteLine("Всего в больнице {0} палат\n", rows);
        for (int i = 0; i < rows; i++)
        {
            Console.WriteLine("В палате {0} находится {1} коек(и).\n", i + 1, columns);
            for (int j = 0; j < columns; j++)
            {
                if (hospital[i * columns + j] != 0 || hospital[i * columns + j] > 0)
                {
                    counter++;
                    Console.WriteLine("В койке {0} лежит пациент с температурой {1}", j + 1, hospital[i * columns + j]);
                }
            }
        }
        patient[] patient_list = new patient[counter];
        Console.WriteLine("\nИнформация о пациентах с одинаковой температурой\n");
        double *check = stackalloc double[counter];

        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < columns; j++)
            {
                for (int y = 0; y < counter; y++)
                {
                    if (check[y] == hospital[i * columns + j])
                    {
                        is_exist = true;
                    }
                }
                if (!is_exist)
                {
                    for (int p = 0; p < counter; p++)
                    {
                        if (check[p] == 0)
                        {
                            check[p] = hospital[i * columns + j]; break;
                        }
                    }
                }
                is_exist = false;
            }
        }
        for (int l = 0; l < patient_list.Length; l++)
        {
            fixed(patient *pointerPatient = &patient_list[l])
            {
                pointerPatient->ward = -1; pointerPatient->cot = -1;
            }
        }
        for (int p = 0; p < counter; p++)
        {
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    if (check[p] == hospital[i * columns + j])
                    {
                        SolvingTaskMassive.EnterIntoStruct(i, j, hospital[i * columns + j], ref patient_list);
                    }
                }
            }
        }
        int counter_for_out = 0;

        for (int i = 0; i < counter; i++)
        {
            for (int j = 0; j < patient_list.Length; j++)
            {
                if (check[i] == patient_list[j].temp)
                {
                    counter_for_out++;
                }
            }
            if (counter_for_out >= 2)
            {
                Console.WriteLine("Пациенты с одинаковой температурой равной {0}\n", check[i]);
                for (int y = 0; y < patient_list.Length; y++)
                {
                    if (check[i] == patient_list[y].temp)
                    {
                        Console.WriteLine("Пациент в палате {0} на койке {1}", patient_list[y].ward + 1, patient_list[y].cot + 1);
                    }
                }
            }
            counter_for_out = 0;
        }
    }
Exemple #4
0
    static public void SimpleMassiveObjective(double[,] hospital)
    {
        bool is_exist = false;

        Console.WriteLine("Всего в больнице {0} палат\n", hospital.Length);
        for (int i = 0; i < hospital.GetLength(0); i++)
        {
            Console.WriteLine("В палате {0} находится {1} коек(и).\n", i + 1, hospital.GetLength(0));
            for (int j = 0; j < hospital.GetLength(1); j++)
            {
                if (hospital[i, j] != 0 || hospital[i, j] > 0)
                {
                    counter++;
                    Console.WriteLine("В койке {0} лежит пациент с температурой {1}", j + 1, hospital[i, j]);
                }
            }
        }
        patient[] patient_list = new patient[counter];
        Console.WriteLine("\nИнформация о пациентах с одинаковой температурой\n");
        double[] check = new double[counter];
        for (int i = 0; i < hospital.GetLength(0); i++)
        {
            for (int j = 0; j < hospital.GetLength(1); j++)
            {
                for (int y = 0; y < check.Length; y++)
                {
                    if (check[y] == hospital[i, j])
                    {
                        is_exist = true;
                    }
                }
                if (!is_exist)
                {
                    for (int p = 0; p < check.Length; p++)
                    {
                        if (check[p] == 0)
                        {
                            check[p] = hospital[i, j]; break;
                        }
                    }
                }
                is_exist = false;
            }
        }
        for (int l = 0; l < patient_list.Length; l++)
        {
            patient_list[l].ward = -1; patient_list[l].cot = -1;
        }
        for (int p = 0; p < check.Length; p++)
        {
            for (int i = 0; i < hospital.GetLength(0); i++)
            {
                for (int j = 0; j < hospital.GetLength(1); j++)
                {
                    if (check[p] == hospital[i, j])
                    {
                        SolvingTaskMassive.EnterIntoStruct(i, j, hospital[i, j], ref patient_list);
                    }
                }
            }
        }
        int counter_for_out = 0;

        for (int i = 0; i < check.Length; i++)
        {
            for (int j = 0; j < patient_list.Length; j++)
            {
                if (check[i] == patient_list[j].temp)
                {
                    counter_for_out++;
                }
            }
            if (counter_for_out >= 2)
            {
                Console.WriteLine("Пациенты с одинаковой температурой равной {0}\n", check[i]);
                for (int y = 0; y < patient_list.Length; y++)
                {
                    if (check[i] == patient_list[y].temp)
                    {
                        Console.WriteLine("Пациент в палате {0} на койке {1}", patient_list[y].ward + 1, patient_list[y].cot + 1);
                    }
                }
            }
            counter_for_out = 0;
        }
    }