abuzik
?>

Вмассиве целых чисел найти группу наименьшей длины, которая состоит из убывающей последовательности четных цифр написать код в с++

Информатика

Ответы

purbuevat56524
#include <iostream>
#include <ctime>

using namespace std;

/* Searching of the minimal sequence of the even numbers. 
 * ARGUMENTS:
 *   - array of the numbers:
 *       int mainArray[];
 *   - number of elements in the array:
 *       int numOfEl;
 * RETURNS: None.
 */
void MinSeqOfNum(int mainArray[], int numOfEl)
{
  int
    minSeqLenght = numOfEl + 1, // минимальная длина последовательности
    seqLenght = 1,  // длина текущей последовательности
    numEnd = 0; // номер элемента, на котором заканчивается последовательность

  /* Цикл обработки массива */
  for (int i = 1; i < numOfEl; i++)
  {
    if (mainArray[i] < mainArray[i - 1] && mainArray[i] % 2 == 0 && mainArray[i - 1] % 2 == 0)
      seqLenght++;
    else
    {
      if (seqLenght < minSeqLenght && seqLenght != 1)
        minSeqLenght = seqLenght, numEnd = i;
      seqLenght = 1;
    }
  }

  /* Дополнительная проверка на случай, если минимальная последовательность    * закончилась на последнем элементе массива */
  if (seqLenght < minSeqLenght && seqLenght != 1)
    minSeqLenght = seqLenght, numEnd = numOfEl;
  if (minSeqLenght != numOfEl + 1)
  {
    cout << endl << endl << "Minimal sequence = " << minSeqLenght << endl << "Group: " << endl;

    /* Вывод группы с минимальной длиной */
    for (int i = numEnd - minSeqLenght; i < numEnd; i++)
      cout << mainArray[i] << "; ";
  }
  else
    cout << endl << endl << "There is no such sequence exists..." << endl;
} /* End of the 'MinSeqOfNum' function */

/* Main program function.
 * ARGUMENTS: None.
 * RETURNS:
 *   (int) errors level for operation system.
 */
int main()
{
  srand(time(0));
  int
    numOfEl,     // кол-во элементов в массиве
    *mainArray;    // основной массив

  /* Инициализация кол-ва элементов массива */
  cout << "Input number of the elements: ";
  cin >> numOfEl;

  /* Выделение памяти под массив */
  if (numOfEl > 0)
    mainArray = new int[numOfEl];
  else
  {
    cout << "Error! Number of the elements cannot be negative!";
    return 0;
  }

  /* Инициализация основного массива случайными значениями */
  for (int i = 0; i < numOfEl; i++)
    mainArray[i] = rand() % 1000;

  /* Инициализация основного массива пользовательскими значениями */
  /*
    for (int i = 0; i < numOfEl; i++)
      cin >> mainArray[i];
  */

  /* Вывод массива */
  for (int i = 0; i < numOfEl; i++)
    cout << mainArray[i] << "; ";

  /// Поиск последовательности убывающих четных чисел ///   MinSeqOfNum(mainArray, numOfEl);

  system("pause");
  return 0;
} /* End of the 'main' function */
kuk-nina

an ancient greek legend, the uninvited wedding goddess of discord and strife eris threw a wedding table a golden apple, on which was written a single word - "the most beautiful". were on olympus hera, athena and aphrodite arguing who should own this apple. each of them was rightfully deserves to own an apple, and even zeus refused to be their judge. he took the apple, gave it to hermes and told to withdraw goddesses in the neighborhood of troy, mount olympus, where they had to decide the dispute son of king priam of troy, paris. hera promised paris power over the whole of asia, athena - the glory and victory, and aphrodite promised him in marriage elenu.uslyhav wonderful promise of aphrodite, paris gave the apple of paris ey.afrodita helped kidnap helen, wife of spartan king menelaus, which later was the cause of the trojan war .

UvarovAndrei

an ancient greek legend, the uninvited wedding goddess of discord and strife eris threw a wedding table a golden apple, on which was written a single word - "the most beautiful". were on olympus hera, athena and aphrodite arguing who should own this apple. each of them was rightfully deserves to own an apple, and even zeus refused to be their judge. he took the apple, gave it to hermes and told to withdraw goddesses in the neighborhood of troy, mount olympus, where they had to decide the dispute son of king priam of troy, paris. hera promised paris power over the whole of asia, athena - the glory and victory, and aphrodite promised him in marriage elenu.uslyhav wonderful promise of aphrodite, paris gave the apple of paris ey.afrodita helped kidnap helen, wife of spartan king menelaus, which later was the cause of the trojan war .

Ответить на вопрос

Поделитесь своими знаниями, ответьте на вопрос:

Вмассиве целых чисел найти группу наименьшей длины, которая состоит из убывающей последовательности четных цифр написать код в с++
Ваше имя (никнейм)*
Email*
Комментарий*

Популярные вопросы в разделе

Allahverdi_Мария475
dobrovolsky-tmz1
dkedrin74038
AkulovaAnastasiya
bondarev05071962
Александровна1973
МАМОНОВА-андрей
Veronika343
nalekseeva62
АлексейГагиковна1774
legezin
windless-el
Artyom
olgabylova6223
inris088