Advertisement
oshige_san

Ex_int

Oct 13th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<conio.h>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7. int main() {
  8.     setlocale(LC_ALL, "");
  9.  
  10.     int* arr = nullptr;
  11.     int l = 0, max = -1, n = 0, m = 0;
  12.  
  13.     string str;
  14.     cout << "Введите количество элементов:" << endl;
  15.  
  16.     while (n <= 0) {
  17.         cin.clear();
  18.         cin.ignore(cin.rdbuf()->in_avail());
  19.         cin >> n;
  20.     }
  21.  
  22.     arr = new(nothrow) int(n);
  23.  
  24.     if (!arr) {
  25.         cout << "Ошибка выделения памяти!";
  26.         return 0;
  27.     }
  28.  
  29.     for (int i = 0; i < n; ) {
  30.         cin.clear();
  31.         cin.ignore(cin.rdbuf()->in_avail());
  32.  
  33.         cout << "Введите элемент[" << i + 1 << "]" << endl;
  34.         cin >> arr[i];
  35.  
  36.         if (cin.peek() != '\n') {
  37.             cout << "Недопустимое значение!" << endl;
  38.             continue;
  39.         }
  40.         i++;
  41.  
  42.     }
  43.     system("cls");
  44.  
  45.     for (int i = 0; i < n; i++)
  46.         cout << arr[i] << endl;
  47.  
  48.     int g = 0;
  49.     int e = 0;
  50.  
  51.     for (int i = 0; i < n; i++) {
  52.         m = arr[i];
  53.        
  54.         g = 0;
  55.        
  56.         while (m) {
  57.             m /= 10;
  58.            
  59.             g++;
  60.            
  61.  
  62.         }
  63.         cout << endl << setw(5) << "i - " << i + 1 << ":";
  64.         if (e < g) {
  65.  
  66.  
  67.  
  68.  
  69.             for (int j = 0; j < n; j++) {
  70.  
  71.  
  72.                 if (i == j)
  73.                     continue;
  74.                 cout << endl << setw(5) << j + 1;
  75.  
  76.                 if (arr[i] == arr[j]) {
  77.                    
  78.                     max = i;
  79.                     cout << "------" << l << endl;
  80.                 }
  81.  
  82.             }
  83.  
  84.         }
  85.  
  86.     }
  87.     if (max == -1) {
  88.         cout << "Нет повторяющихся последовательностей!";
  89.         return 134;
  90.     }
  91.  
  92.     cout << endl << setw(40) << "Нужная последовательность:" << setw(6) << max + 1 << setw(6) << arr[max];
  93.     return 0;
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement