Vlad5080

...

Jan 25th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. void ex1() {
  2.     int a, b, c, n, k=0;
  3.         int temp;
  4.  
  5.     cout << "Кол-во элементов \n ->";
  6.     cin >> n;
  7.     int* arr = new int[n];
  8.  
  9.     cout << "Введите элементы\n ->";
  10.     for (int i = 0; i < n; i++) {
  11.         cin >> arr[i];
  12.     }
  13.  
  14.     for (int i = 0; i < n; i++) {
  15.         cout << arr[i]<< " ";
  16.     }
  17.  
  18.     cout << endl;
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         for (int j = i; j < n; j++)
  22.         {
  23.             if (arr[i] == arr[j]) {
  24.                 k++;
  25.                 break;
  26.             }
  27.         }
  28.     }
  29.  
  30.         int* arr2 = new int[k];
  31.         c = 0;
  32.  
  33.         for (int i = 0; i < n; i++)
  34.         {
  35.             for (int j = i; j < n; j++)
  36.             {
  37.                 if (arr[i] == arr[j]) {
  38.                     arr2[c] = arr[i];
  39.                     c++;
  40.                     break;
  41.                 }
  42.             }
  43.         }
  44.  
  45.         cout << "Повторений " << c << endl;
  46.  
  47.         for (int i = k - 1; i >= 1; i--) {
  48.             for (int j = 0; j < i; j++) {
  49.                 if (arr2[j] > arr2[j + 1]) {
  50.                     temp = arr2[j];
  51.                     arr2[j] = arr2[j + 1];
  52.                     arr2[j + 1] = temp;
  53.                 }
  54.             }
  55.  
  56.         }
  57.         for (int i = 0; i < k; i++) {
  58.             cout << arr2[i] << " ";
  59.         }
  60.         cout << endl;
  61.  
  62.  
  63.    
  64. }
  65.  
  66. int main() {
  67.     setlocale(0, "");
  68.  
  69.     ex1();
  70.     // ex2();
  71.  
  72.  
  73.  
  74.     system("pause");
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment