Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. void Show(int A[], int n)
  9. {
  10.     int Max = 0, max, x = n + 1;
  11.     for (int i = 0; i < n; i++)
  12.     {
  13.         max = 0;
  14.         for (int j = i; j < n - 1; j++)
  15.         {
  16.             if (A[j+1] % A[j] == 0)
  17.             {
  18.                 max = j + 1;
  19.             }
  20.             else
  21.             {
  22.                 break;
  23.             }
  24.         }
  25.         if(Max < abs(Max - max))
  26.         {
  27.             Max = max;
  28.             x = i;
  29.         }
  30.     }
  31.     cout << "Максивальнно длинная строка: ";
  32.     for (int i = x; i <= Max; i++)
  33.     {
  34.         cout << A[i] << " ";
  35.     }
  36. }
  37. int main()
  38. {
  39.     setlocale(0,"RUS");
  40.    
  41.     int A[100] = {}, n;
  42.    
  43.     cout << "Введите длинну последовательности: ";
  44.     cin >> n;
  45.    
  46.     if(n > 0)
  47.     {
  48.         for (int i = 0; i < n; i++)
  49.         {
  50.             s:
  51.             cout << "Введите " << i + 1 << " число: ";
  52.             cin >> A[i];
  53.             if(A[i] <= 0)
  54.             {
  55.                 cout << "Ошибка ввода" << endl;
  56.                 goto s;
  57.             }
  58.         }  
  59.         cout << "Последовательность: ";
  60.         for (int i = 0; i < n; i++)
  61.         {
  62.             cout << A[i] << " ";    
  63.         }
  64.         cout << endl;
  65.         if (n > 1)
  66.         {
  67.             Show(A, n);
  68.         }
  69.         else
  70.         {
  71.             cout << "Максивальнно длинная строка: " << A[0] << endl;
  72.         }
  73.         cout << endl;
  74.         system("pause");
  75.     }
  76.     else
  77.     {
  78.         cout << "Введите данные корректно!" << endl;
  79.     }
  80.     return main();
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement